@rspack/cli 0.0.0-1bce45e7c0-20221109113710

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/bin/rspack ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ try {
3
+ require("source-map-support").install({
4
+ handleUncaughtExceptions: false
5
+ });
6
+ } catch (err) {}
7
+ const runCLI = require("../dist/bootstrap").runCLI;
8
+ runCLI(process.argv);
@@ -0,0 +1,2 @@
1
+ export declare function runCLI(argv: string[]): Promise<void>;
2
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAEA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,iBAG1C"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCLI = void 0;
4
+ const rspack_cli_1 = require("./rspack-cli");
5
+ async function runCLI(argv) {
6
+ const cli = new rspack_cli_1.RspackCLI();
7
+ await cli.run(argv);
8
+ }
9
+ exports.runCLI = runCLI;
10
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AAElC,KAAK,UAAU,MAAM,CAAC,IAAc;IAC1C,MAAM,GAAG,GAAG,IAAI,sBAAS,EAAE,CAAC;IAC5B,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC;AAHD,wBAGC"}
@@ -0,0 +1,6 @@
1
+ import type { RspackCLI } from "../rspack-cli";
2
+ import { RspackCommand } from "../types";
3
+ export declare class BuildCommand implements RspackCommand {
4
+ apply(cli: RspackCLI): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,qBAAa,YAAa,YAAW,aAAa;IAC3C,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CA6E1C"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.BuildCommand = void 0;
27
+ const fs = __importStar(require("fs"));
28
+ const options_1 = require("../utils/options");
29
+ class BuildCommand {
30
+ async apply(cli) {
31
+ cli.program.command(["build [entry..]", "$0", "bundle", "b"], "run the rspack build", yargs => (0, options_1.commonOptions)(yargs).options({
32
+ analyze: {
33
+ type: "boolean",
34
+ default: false,
35
+ describe: "analyze"
36
+ },
37
+ json: {
38
+ describe: "emit stats json"
39
+ }
40
+ }), async (options) => {
41
+ const logger = cli.getLogger();
42
+ let createJsonStringifyStream;
43
+ if (options.json) {
44
+ const jsonExt = await Promise.resolve().then(() => __importStar(require("@discoveryjs/json-ext")));
45
+ createJsonStringifyStream = jsonExt.stringifyStream;
46
+ }
47
+ const callback = (error, stats) => {
48
+ if (error) {
49
+ logger.error(error);
50
+ process.exit(2);
51
+ }
52
+ if (stats && stats.hasErrors()) {
53
+ process.exitCode = 1;
54
+ }
55
+ if (!compiler || !stats) {
56
+ return;
57
+ }
58
+ const statsOptions = compiler.options
59
+ ? compiler.options.stats
60
+ : undefined;
61
+ if (options.json && createJsonStringifyStream) {
62
+ const handleWriteError = error => {
63
+ logger.error(error);
64
+ process.exit(2);
65
+ };
66
+ if (options.json === true) {
67
+ createJsonStringifyStream(stats.toJson(statsOptions))
68
+ .on("error", handleWriteError)
69
+ .pipe(process.stdout)
70
+ .on("error", handleWriteError)
71
+ .on("close", () => process.stdout.write("\n"));
72
+ }
73
+ else if (typeof options.json === "string") {
74
+ createJsonStringifyStream(stats.toJson(statsOptions))
75
+ .on("error", handleWriteError)
76
+ .pipe(fs.createWriteStream(options.json))
77
+ .on("error", handleWriteError)
78
+ // Use stderr to logging
79
+ .on("close", () => {
80
+ process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
81
+ });
82
+ }
83
+ }
84
+ else {
85
+ const printedStats = stats.toString(statsOptions);
86
+ // Avoid extra empty line when `stats: 'none'`
87
+ if (printedStats) {
88
+ logger.raw(printedStats);
89
+ }
90
+ }
91
+ };
92
+ console.time("build");
93
+ const compiler = await cli.createCompiler(options);
94
+ compiler.run(callback);
95
+ console.timeEnd("build");
96
+ });
97
+ }
98
+ }
99
+ exports.BuildCommand = BuildCommand;
100
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],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MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;qBACzB;iBACD;YACF,CAAC,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YACnD,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACvB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC,CACD,CAAC;IACH,CAAC;CACD;AA9ED,oCA8EC"}
@@ -0,0 +1,6 @@
1
+ import type { RspackCLI } from "../rspack-cli";
2
+ import { RspackCommand } from "../types";
3
+ export declare class ServeCommand implements RspackCommand {
4
+ apply(cli: RspackCLI): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/commands/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,qBAAa,YAAa,YAAW,aAAa;IAC3C,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAY1C"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServeCommand = void 0;
4
+ const dev_server_1 = require("@rspack/dev-server");
5
+ const options_1 = require("../utils/options");
6
+ class ServeCommand {
7
+ async apply(cli) {
8
+ cli.program.command(["serve [entry..]", "server", "s"], "run the rspack dev server.", options_1.commonOptions, async (options) => {
9
+ const compiler = await cli.createCompiler(options);
10
+ const server = new dev_server_1.RspackDevServer(compiler);
11
+ await server.start();
12
+ });
13
+ }
14
+ }
15
+ exports.ServeCommand = ServeCommand;
16
+ //# sourceMappingURL=serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/commands/serve.ts"],"names":[],"mappings":";;;AACA,mDAAqD;AAErD,8CAAiD;AAEjD,MAAa,YAAY;IACxB,KAAK,CAAC,KAAK,CAAC,GAAc;QACzB,GAAG,CAAC,OAAO,CAAC,OAAO,CAClB,CAAC,iBAAiB,EAAE,QAAQ,EAAE,GAAG,CAAC,EAClC,4BAA4B,EAC5B,uBAAa,EACb,KAAK,EAAC,OAAO,EAAC,EAAE;YACf,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YACnD,MAAM,MAAM,GAAG,IAAI,4BAAe,CAAC,QAAQ,CAAC,CAAC;YAC7C,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC,CACD,CAAC;IACH,CAAC;CACD;AAbD,oCAaC"}
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export { RspackCLI } from "./rspack-cli";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.RspackCLI = void 0;
18
+ __exportStar(require("./types"), exports);
19
+ var rspack_cli_1 = require("./rspack-cli");
20
+ Object.defineProperty(exports, "RspackCLI", { enumerable: true, get: function () { return rspack_cli_1.RspackCLI; } });
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,0CAAwB;AACxB,2CAAyC;AAAhC,uGAAA,SAAS,OAAA"}
@@ -0,0 +1,16 @@
1
+ import yargs from "yargs";
2
+ import { RspackCLIColors, RspackCLILogger, RspackCLIOptions } from "./types";
3
+ import { RspackOptions } from "@rspack/core";
4
+ export declare class RspackCLI {
5
+ colors: RspackCLIColors;
6
+ program: yargs.Argv<{}>;
7
+ constructor();
8
+ createCompiler(options: RspackCLIOptions): Promise<import("@rspack/core/dist/compiler").Compiler>;
9
+ createColors(useColor?: boolean): RspackCLIColors;
10
+ getLogger(): RspackCLILogger;
11
+ run(argv: string[]): Promise<void>;
12
+ registerCommands(): Promise<void>;
13
+ buildConfig(item: any, options: RspackCLIOptions): Promise<any>;
14
+ loadConfig(options: RspackCLIOptions): Promise<RspackOptions>;
15
+ }
16
+ //# sourceMappingURL=rspack-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rspack-cli.d.ts","sourceRoot":"","sources":["../src/rspack-cli.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG7E,OAAO,EAAU,aAAa,EAAkB,MAAM,cAAc,CAAC;AAIrE,qBAAa,SAAS;IACrB,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;;IAKlB,cAAc,CAAC,OAAO,EAAE,gBAAgB;IAM9C,YAAY,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,eAAe;IAgBjD,SAAS,IAAI,eAAe;IAWtB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE;IAMlB,gBAAgB;IAMhB,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,gBAAgB;IAgChD,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;CAoCnE"}
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.RspackCLI = void 0;
30
+ const helpers_1 = require("yargs/helpers");
31
+ const yargs_1 = __importDefault(require("yargs"));
32
+ const util_1 = __importDefault(require("util"));
33
+ const path_1 = __importDefault(require("path"));
34
+ const fs_1 = __importDefault(require("fs"));
35
+ const build_1 = require("./commands/build");
36
+ const serve_1 = require("./commands/serve");
37
+ const core_1 = require("@rspack/core");
38
+ const defaultConfig = "rspack.config.js";
39
+ const defaultEntry = "src/index.js";
40
+ class RspackCLI {
41
+ constructor() {
42
+ this.colors = this.createColors();
43
+ this.program = (0, yargs_1.default)();
44
+ }
45
+ async createCompiler(options) {
46
+ let config = await this.loadConfig(options);
47
+ config = await this.buildConfig(config, options);
48
+ const compiler = (0, core_1.createCompiler)(config);
49
+ return compiler;
50
+ }
51
+ createColors(useColor) {
52
+ const { createColors, isColorSupported } = require("colorette");
53
+ let shouldUseColor;
54
+ if (useColor) {
55
+ shouldUseColor = useColor;
56
+ }
57
+ else {
58
+ shouldUseColor = isColorSupported;
59
+ }
60
+ return {
61
+ ...createColors({ useColor: shouldUseColor }),
62
+ isColorSupported: shouldUseColor
63
+ };
64
+ }
65
+ getLogger() {
66
+ return {
67
+ error: val => console.error(`[rspack-cli] ${this.colors.red(util_1.default.format(val))}`),
68
+ warn: val => console.warn(`[rspack-cli] ${this.colors.yellow(val)}`),
69
+ info: val => console.info(`[rspack-cli] ${this.colors.cyan(val)}`),
70
+ success: val => console.log(`[rspack-cli] ${this.colors.green(val)}`),
71
+ log: val => console.log(`[rspack-cli] ${val}`),
72
+ raw: val => console.log(val)
73
+ };
74
+ }
75
+ async run(argv) {
76
+ this.program.usage("[options]");
77
+ this.program.scriptName("rspack");
78
+ this.registerCommands();
79
+ await this.program.parseAsync((0, helpers_1.hideBin)(argv));
80
+ }
81
+ async registerCommands() {
82
+ const builtinCommands = [new build_1.BuildCommand(), new serve_1.ServeCommand()];
83
+ for (const command of builtinCommands) {
84
+ command.apply(this);
85
+ }
86
+ }
87
+ async buildConfig(item, options) {
88
+ var _a;
89
+ if (options.analyze) {
90
+ const { BundleAnalyzerPlugin } = await Promise.resolve().then(() => __importStar(require("webpack-bundle-analyzer")));
91
+ ((_a = item.plugins) !== null && _a !== void 0 ? _a : (item.plugins = [])).push({
92
+ name: "rspack-bundle-analyzer",
93
+ apply(compiler) {
94
+ new BundleAnalyzerPlugin({
95
+ generateStatsFile: true,
96
+ // TODO: delete this once runtime refacted.
97
+ excludeAssets: "runtime.js"
98
+ }).apply(compiler);
99
+ }
100
+ });
101
+ }
102
+ if (options.mode) {
103
+ item.mode = options.mode;
104
+ }
105
+ if (!item.mode &&
106
+ process.env &&
107
+ process.env.NODE_ENV &&
108
+ (process.env.NODE_ENV === "development" ||
109
+ process.env.NODE_ENV === "production" ||
110
+ process.env.NODE_ENV === "none")) {
111
+ item.mode = process.env.NODE_ENV;
112
+ }
113
+ if (!item.mode) {
114
+ item.mode = "production";
115
+ }
116
+ return item;
117
+ }
118
+ async loadConfig(options) {
119
+ var _a;
120
+ let loadedConfig;
121
+ // if we pass config paras
122
+ if (options.config) {
123
+ const resolvedConfigPath = path_1.default.resolve(process.cwd(), options.config);
124
+ if (!fs_1.default.existsSync(resolvedConfigPath)) {
125
+ throw new Error(`config file "${resolvedConfigPath}" not exists`);
126
+ }
127
+ loadedConfig = require(resolvedConfigPath);
128
+ }
129
+ else {
130
+ let defaultConfigPath = path_1.default.resolve(process.cwd(), defaultConfig);
131
+ if (fs_1.default.existsSync(defaultConfigPath)) {
132
+ loadedConfig = require(defaultConfigPath);
133
+ }
134
+ else {
135
+ let entry = {};
136
+ if (options.entry) {
137
+ console.log("entry:", options.entry);
138
+ entry = {
139
+ main: options.entry.map(x => path_1.default.resolve(process.cwd(), x))[0] // Fix me when entry supports array
140
+ };
141
+ }
142
+ else {
143
+ entry = {
144
+ main: path_1.default.resolve(process.cwd(), defaultEntry)
145
+ };
146
+ }
147
+ loadedConfig = {
148
+ entry
149
+ };
150
+ }
151
+ }
152
+ (_a = loadedConfig.stats) !== null && _a !== void 0 ? _a : (loadedConfig.stats = {});
153
+ if (this.colors.isColorSupported) {
154
+ loadedConfig.stats.colors = true;
155
+ }
156
+ return loadedConfig;
157
+ }
158
+ }
159
+ exports.RspackCLI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HC"}
@@ -0,0 +1,33 @@
1
+ import { Colorette } from "colorette";
2
+ import { RspackCLI } from "./rspack-cli";
3
+ import { WebpackOptionsNormalized } from "webpack";
4
+ export type { Configuration } from "@rspack/core";
5
+ import { Configuration as DevServerConfig } from "webpack-dev-server";
6
+ export interface IRspackCLI {
7
+ runRspack(): Promise<void>;
8
+ }
9
+ export declare type LogHandler = (value: any) => void;
10
+ export interface RspackCLIColors extends Colorette {
11
+ isColorSupported: boolean;
12
+ }
13
+ export interface RspackCLILogger {
14
+ error: LogHandler;
15
+ warn: LogHandler;
16
+ info: LogHandler;
17
+ success: LogHandler;
18
+ log: LogHandler;
19
+ raw: LogHandler;
20
+ }
21
+ export interface RspackCLIOptions {
22
+ entry?: string[];
23
+ config?: string;
24
+ devtool?: boolean;
25
+ mode?: string;
26
+ watch?: boolean;
27
+ analyze?: boolean;
28
+ }
29
+ export interface RspackCommand {
30
+ apply(cli: RspackCLI): Promise<void>;
31
+ }
32
+ export declare type RspackDevServerOptions = DevServerConfig & WebpackOptionsNormalized;
33
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACtE,MAAM,WAAW,UAAU;IAC1B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AACD,oBAAY,UAAU,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AAC9C,MAAM,WAAW,eAAgB,SAAQ,SAAS;IACjD,gBAAgB,EAAE,OAAO,CAAC;CAC1B;AACD,MAAM,WAAW,eAAe;IAC/B,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,UAAU,CAAC;IACpB,GAAG,EAAE,UAAU,CAAC;IAChB,GAAG,EAAE,UAAU,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAChC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC7B,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AACD,oBAAY,sBAAsB,GAAG,eAAe,GAAG,wBAAwB,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import yargs from "yargs";
2
+ export declare const commonOptions: (yargs: yargs.Argv<{}>) => yargs.Argv<yargs.Omit<{
3
+ entry: string[];
4
+ }, "config" | "watch" | "mode" | "devtool"> & yargs.InferredOptionTypes<{
5
+ config: {
6
+ g: boolean;
7
+ type: "string";
8
+ describe: string;
9
+ alias: string;
10
+ };
11
+ mode: {
12
+ type: "string";
13
+ describe: string;
14
+ };
15
+ watch: {
16
+ type: "boolean";
17
+ default: boolean;
18
+ describe: string;
19
+ };
20
+ devtool: {
21
+ type: "boolean";
22
+ default: boolean;
23
+ describe: string;
24
+ };
25
+ }>>;
26
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/utils/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;GA0BzB,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commonOptions = void 0;
4
+ const commonOptions = (yargs) => {
5
+ return yargs
6
+ .positional("entry", {
7
+ type: "string",
8
+ array: true,
9
+ describe: "entry"
10
+ })
11
+ .options({
12
+ config: {
13
+ g: true,
14
+ type: "string",
15
+ describe: "config file",
16
+ alias: "c"
17
+ },
18
+ mode: { type: "string", describe: "mode" },
19
+ watch: {
20
+ type: "boolean",
21
+ default: false,
22
+ describe: "watch"
23
+ },
24
+ devtool: {
25
+ type: "boolean",
26
+ default: false,
27
+ describe: "devtool"
28
+ }
29
+ });
30
+ };
31
+ exports.commonOptions = commonOptions;
32
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/utils/options.ts"],"names":[],"mappings":";;;AACO,MAAM,aAAa,GAAG,CAAC,KAAqB,EAAE,EAAE;IACtD,OAAO,KAAK;SACV,UAAU,CAAC,OAAO,EAAE;QACpB,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,OAAO;KACjB,CAAC;SACD,OAAO,CAAC;QACR,MAAM,EAAE;YACP,CAAC,EAAE,IAAI;YACP,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,aAAa;YACvB,KAAK,EAAE,GAAG;SACV;QACD,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE;QAC1C,KAAK,EAAE;YACN,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,OAAO;SACjB;QACD,OAAO,EAAE;YACR,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,SAAS;SACnB;KACD,CAAC,CAAC;AACL,CAAC,CAAC;AA1BW,QAAA,aAAa,iBA0BxB"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@rspack/cli",
3
+ "version": "0.0.0-1bce45e7c0-20221109113710",
4
+ "bin": {
5
+ "rspack": "./bin/rspack"
6
+ },
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "bin",
11
+ "dist"
12
+ ],
13
+ "devDependencies": {
14
+ "@types/webpack-bundle-analyzer": "^4.6.0",
15
+ "concat-stream": "^2.0.0",
16
+ "execa": "^5.0.0",
17
+ "internal-ip": "6.2.0",
18
+ "source-map-support": "^0.5.19"
19
+ },
20
+ "dependencies": {
21
+ "@discoveryjs/json-ext": "^0.5.7",
22
+ "@rspack/core": "0.0.0-1bce45e7c0-20221109113710",
23
+ "@rspack/dev-server": "0.0.0-1bce45e7c0-20221109113710",
24
+ "colorette": "2.0.19",
25
+ "webpack": "5.74.0",
26
+ "webpack-bundle-analyzer": "4.6.1",
27
+ "webpack-dev-server": "4.11.1",
28
+ "yargs": "17.5.1"
29
+ },
30
+ "scripts": {
31
+ "build": "rm -rf dist/ && tsc -b --force",
32
+ "dev": "tsc -b -w",
33
+ "test": "jest --verbose"
34
+ }
35
+ }