@rspack-debug/cli 1.3.14

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 ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-present Bytedance, Inc. and its affiliates.
4
+
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ <picture>
2
+ <img alt="Rspack Banner" src="https://assets.rspack.rs/rspack/rspack-banner.png">
3
+ </picture>
4
+
5
+ # @rspack/cli
6
+
7
+ Command-line interface for rspack.
8
+
9
+ ## Documentation
10
+
11
+ See [https://rspack.rs](https://rspack.rs) for details.
12
+
13
+ ## License
14
+
15
+ Rspack is [MIT licensed](https://github.com/web-infra-dev/rspack/blob/main/LICENSE).
package/bin/rspack.js ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ const nodeModule = require("node:module");
3
+
4
+ // enable on-disk code caching of all modules loaded by Node.js
5
+ // requires Nodejs >= 22.8.0
6
+ const { enableCompileCache } = nodeModule;
7
+ if (enableCompileCache) {
8
+ try {
9
+ enableCompileCache();
10
+ } catch {
11
+ // ignore errors
12
+ }
13
+ }
14
+
15
+ // make it easier to identify the process via activity monitor or other tools
16
+ process.title = "rspack-node";
17
+
18
+ const { RspackCLI } = require("../dist/index");
19
+
20
+ async function runCLI() {
21
+ const cli = new RspackCLI();
22
+ await cli.run(process.argv);
23
+ }
24
+
25
+ runCLI();
package/dist/556.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ exports.ids = [
3
+ "556"
4
+ ];
5
+ exports.modules = {
6
+ "./src/utils/profile.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
7
+ __webpack_require__.d(__webpack_exports__, {
8
+ applyProfile: ()=>applyProfile
9
+ });
10
+ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:fs");
11
+ var node_fs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/ __webpack_require__.n(node_fs__WEBPACK_IMPORTED_MODULE_0__);
12
+ var node_path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("node:path");
13
+ var node_path__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/ __webpack_require__.n(node_path__WEBPACK_IMPORTED_MODULE_1__);
14
+ var _rspack_core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("@rspack/core");
15
+ const overviewTraceFilter = "info";
16
+ const allTraceFilter = "trace";
17
+ const defaultRustTraceLayer = "chrome";
18
+ function resolveLayer(value) {
19
+ if ("OVERVIEW" === value) return overviewTraceFilter;
20
+ if ("ALL" === value) return allTraceFilter;
21
+ return value;
22
+ }
23
+ async function applyProfile(filterValue, traceLayer = defaultRustTraceLayer, traceOutput) {
24
+ const { asyncExitHook } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "exit-hook"));
25
+ if ("chrome" !== traceLayer && "logger" !== traceLayer) throw new Error(`unsupported trace layer: ${traceLayer}`);
26
+ if (!traceOutput) {
27
+ const timestamp = Date.now();
28
+ const defaultOutputDir = node_path__WEBPACK_IMPORTED_MODULE_1___default().resolve(`.rspack-profile-${timestamp}-${process.pid}`);
29
+ const defaultRustTraceChromeOutput = node_path__WEBPACK_IMPORTED_MODULE_1___default().join(defaultOutputDir, "trace.json");
30
+ const defaultRustTraceLoggerOutput = "stdout";
31
+ const defaultTraceOutput = "chrome" === traceLayer ? defaultRustTraceChromeOutput : defaultRustTraceLoggerOutput;
32
+ traceOutput = defaultTraceOutput;
33
+ }
34
+ const filter = resolveLayer(filterValue);
35
+ await ensureFileDir(traceOutput);
36
+ await _rspack_core__WEBPACK_IMPORTED_MODULE_2__.rspack.experiments.globalTrace.register(filter, traceLayer, traceOutput);
37
+ asyncExitHook(_rspack_core__WEBPACK_IMPORTED_MODULE_2__.rspack.experiments.globalTrace.cleanup, {
38
+ wait: 500
39
+ });
40
+ }
41
+ async function ensureFileDir(outputFilePath) {
42
+ const dir = node_path__WEBPACK_IMPORTED_MODULE_1___default().dirname(outputFilePath);
43
+ await node_fs__WEBPACK_IMPORTED_MODULE_0___default().promises.mkdir(dir, {
44
+ recursive: true
45
+ });
46
+ }
47
+ }
48
+ };
package/dist/556.mjs ADDED
@@ -0,0 +1,45 @@
1
+ export const __webpack_ids__ = [
2
+ "556"
3
+ ];
4
+ export const __webpack_modules__ = {
5
+ "./src/utils/profile.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
6
+ __webpack_require__.d(__webpack_exports__, {
7
+ applyProfile: ()=>applyProfile
8
+ });
9
+ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:fs");
10
+ var node_path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("node:path");
11
+ var _rspack_core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("@rspack/core");
12
+ const overviewTraceFilter = "info";
13
+ const allTraceFilter = "trace";
14
+ const defaultRustTraceLayer = "chrome";
15
+ function resolveLayer(value) {
16
+ if ("OVERVIEW" === value) return overviewTraceFilter;
17
+ if ("ALL" === value) return allTraceFilter;
18
+ return value;
19
+ }
20
+ async function applyProfile(filterValue, traceLayer = defaultRustTraceLayer, traceOutput) {
21
+ const { asyncExitHook } = await import("exit-hook");
22
+ if ("chrome" !== traceLayer && "logger" !== traceLayer) throw new Error(`unsupported trace layer: ${traceLayer}`);
23
+ if (!traceOutput) {
24
+ const timestamp = Date.now();
25
+ const defaultOutputDir = node_path__WEBPACK_IMPORTED_MODULE_1__["default"].resolve(`.rspack-profile-${timestamp}-${process.pid}`);
26
+ const defaultRustTraceChromeOutput = node_path__WEBPACK_IMPORTED_MODULE_1__["default"].join(defaultOutputDir, "trace.json");
27
+ const defaultRustTraceLoggerOutput = "stdout";
28
+ const defaultTraceOutput = "chrome" === traceLayer ? defaultRustTraceChromeOutput : defaultRustTraceLoggerOutput;
29
+ traceOutput = defaultTraceOutput;
30
+ }
31
+ const filter = resolveLayer(filterValue);
32
+ await ensureFileDir(traceOutput);
33
+ await _rspack_core__WEBPACK_IMPORTED_MODULE_2__.rspack.experiments.globalTrace.register(filter, traceLayer, traceOutput);
34
+ asyncExitHook(_rspack_core__WEBPACK_IMPORTED_MODULE_2__.rspack.experiments.globalTrace.cleanup, {
35
+ wait: 500
36
+ });
37
+ }
38
+ async function ensureFileDir(outputFilePath) {
39
+ const dir = node_path__WEBPACK_IMPORTED_MODULE_1__["default"].dirname(outputFilePath);
40
+ await node_fs__WEBPACK_IMPORTED_MODULE_0__["default"].promises.mkdir(dir, {
41
+ recursive: true
42
+ });
43
+ }
44
+ }
45
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import type { RspackPluginFunction, RspackPluginInstance } from "@rspack/core";
2
+ import { type Compiler, type MultiCompiler, type MultiRspackOptions, type MultiStats, type RspackOptions, type Stats } from "@rspack/core";
3
+ import yargs from "yargs";
4
+ import type { RspackBuildCLIOptions, RspackCLIColors, RspackCLILogger, RspackCLIOptions } from "./types";
5
+ type Command = "serve" | "build";
6
+ export declare class RspackCLI {
7
+ colors: RspackCLIColors;
8
+ program: yargs.Argv;
9
+ constructor();
10
+ createCompiler(options: RspackBuildCLIOptions, rspackCommand: Command, callback?: (e: Error | null, res?: Stats | MultiStats) => void): Promise<MultiCompiler | Compiler | null>;
11
+ createColors(useColor?: boolean): RspackCLIColors;
12
+ getLogger(): RspackCLILogger;
13
+ run(argv: string[]): Promise<void>;
14
+ registerCommands(): Promise<void>;
15
+ buildConfig(item: RspackOptions | MultiRspackOptions, options: RspackBuildCLIOptions, command: Command): Promise<RspackOptions | MultiRspackOptions>;
16
+ loadConfig(options: RspackCLIOptions): Promise<RspackOptions | MultiRspackOptions>;
17
+ isMultipleCompiler(compiler: Compiler | MultiCompiler): compiler is MultiCompiler;
18
+ isWatch(compiler: Compiler | MultiCompiler): boolean;
19
+ }
20
+ export type RspackConfigFn = (env: Record<string, any>, argv: Record<string, any>) => RspackOptions | MultiRspackOptions;
21
+ export type RspackConfigAsyncFn = (env: Record<string, any>, argv: Record<string, any>) => Promise<RspackOptions | MultiRspackOptions>;
22
+ export type RspackConfigExport = RspackOptions | MultiRspackOptions | RspackConfigFn | RspackConfigAsyncFn;
23
+ /**
24
+ * This function helps you to autocomplete configuration types.
25
+ * It accepts a Rspack config object, or a function that returns a config.
26
+ */
27
+ export declare function defineConfig(config: RspackOptions): RspackOptions;
28
+ export declare function defineConfig(config: MultiRspackOptions): MultiRspackOptions;
29
+ export declare function defineConfig(config: RspackConfigFn): RspackConfigFn;
30
+ export declare function defineConfig(config: RspackConfigAsyncFn): RspackConfigAsyncFn;
31
+ export declare function defineConfig(config: RspackConfigExport): RspackConfigExport;
32
+ export declare function definePlugin(plugin: RspackPluginFunction): RspackPluginFunction;
33
+ export declare function definePlugin(plugin: RspackPluginInstance): RspackPluginInstance;
34
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { RspackCLI } from "../cli";
2
+ import type { RspackCommand } from "../types";
3
+ export declare class BuildCommand implements RspackCommand {
4
+ apply(cli: RspackCLI): Promise<void>;
5
+ }
@@ -0,0 +1,5 @@
1
+ import type { RspackCLI } from "../cli";
2
+ import type { RspackCommand } from "../types";
3
+ export declare class PreviewCommand implements RspackCommand {
4
+ apply(cli: RspackCLI): Promise<void>;
5
+ }
@@ -0,0 +1,5 @@
1
+ import type { RspackCLI } from "../cli";
2
+ import type { RspackCommand } from "../types";
3
+ export declare class ServeCommand implements RspackCommand {
4
+ apply(cli: RspackCLI): Promise<void>;
5
+ }
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_CONFIG_NAME: "rspack.config";
2
+ export declare const DEFAULT_EXTENSIONS: readonly [".js", ".ts", ".mjs", ".mts", ".cjs", ".cts"];
@@ -0,0 +1,2 @@
1
+ export { defineConfig, definePlugin, RspackCLI } from "./cli";
2
+ export * from "./types";