@rspack-debug/cli
Advanced tools
+2
-2
@@ -259,3 +259,3 @@ import type { Compiler } from '@rspack/core'; | ||
| buildCompilerConfig(options: CommonOptionsForBuildAndServe, rspackCommand: Command_2): Promise<RspackOptions | MultiRspackOptions>; | ||
| createCompiler(config: RspackOptions | MultiRspackOptions, callback?: (e: Error | null, res?: Stats | MultiStats) => void): Promise<MultiCompiler | Compiler | null>; | ||
| createCompiler(config: RspackOptions | MultiRspackOptions, callback?: (e: Error | null, res?: Stats | MultiStats) => void): Compiler | MultiCompiler | null; | ||
| private createColors; | ||
@@ -293,3 +293,3 @@ getLogger(): RspackCLILogger; | ||
| export declare interface RspackCommand { | ||
| apply(cli: RspackCLI): Promise<void>; | ||
| apply(cli: RspackCLI): void | Promise<void>; | ||
| } | ||
@@ -296,0 +296,0 @@ |
+117
-14
@@ -7,3 +7,3 @@ import node_path from "node:path"; | ||
| import { createRequire } from "node:module"; | ||
| import { pathToFileURL } from "node:url"; | ||
| import { fileURLToPath, pathToFileURL } from "node:url"; | ||
| function toArr(any) { | ||
@@ -679,3 +679,3 @@ return null == any ? [] : Array.isArray(any) ? any : [ | ||
| class BuildCommand { | ||
| async apply(cli) { | ||
| apply(cli) { | ||
| const command = cli.program.command('', 'run the Rspack build').alias('build').alias('bundle').alias('b'); | ||
@@ -689,3 +689,3 @@ commonOptionsForBuildAndServe(commonOptions(command)).option('--json [path]', 'emit stats json'); | ||
| class PreviewCommand { | ||
| async apply(cli) { | ||
| apply(cli) { | ||
| const command = cli.program.command('preview [dir]', 'run the Rspack server for build output').alias('p'); | ||
@@ -730,3 +730,3 @@ commonOptions(command).option('--public-path <path>', 'static resource server path').option('--port <port>', 'preview server port').option('--host <host>', 'preview server host').option('--open', 'open browser').option('--server <config>', 'Configuration items for the server.'); | ||
| const DEFAULT_ROOT = 'dist'; | ||
| const internalPreviewConfig = async (item)=>{ | ||
| const internalPreviewConfig = (item)=>{ | ||
| const devServer = false === item.devServer ? void 0 : item.devServer; | ||
@@ -757,3 +757,3 @@ item.devServer = { | ||
| class ServeCommand { | ||
| async apply(cli) { | ||
| apply(cli) { | ||
| const command = cli.program.command('serve', 'run the rspack dev server.').alias('server').alias('s').alias('dev'); | ||
@@ -856,2 +856,96 @@ commonOptionsForBuildAndServe(commonOptions(command)).option('--hot [mode]', 'enables hot module replacement').option('--port <port>', 'allows to specify a port to use').option('--host <host>', 'allows to specify a hostname to use').option('--open [value]', 'open browser on server start; pass --no-open to disable, or --open <url> to open a specific URL'); | ||
| } | ||
| function mergeWith(objects, customizer) { | ||
| const [first, ...rest] = objects; | ||
| let ret = first; | ||
| rest.forEach((a)=>{ | ||
| ret = mergeTo(ret, a, customizer); | ||
| }); | ||
| return ret; | ||
| } | ||
| function mergeTo(a, b, customizer) { | ||
| const ret = {}; | ||
| Object.keys(a).concat(Object.keys(b)).forEach((k)=>{ | ||
| const v = customizer(a[k], b[k], k); | ||
| ret[k] = void 0 === v ? a[k] : v; | ||
| }); | ||
| return ret; | ||
| } | ||
| const merge_with = mergeWith; | ||
| function isRegex(o) { | ||
| return o instanceof RegExp; | ||
| } | ||
| function isPlainObject(value) { | ||
| if ('[object Object]' !== Object.prototype.toString.call(value)) return false; | ||
| const proto = Object.getPrototypeOf(value); | ||
| if (null === proto) return true; | ||
| let baseProto = proto; | ||
| while(null !== Object.getPrototypeOf(baseProto))baseProto = Object.getPrototypeOf(baseProto); | ||
| return proto === baseProto; | ||
| } | ||
| function isUndefined(value) { | ||
| return void 0 === value; | ||
| } | ||
| function isPromiseLike(value) { | ||
| return null !== value && ('object' == typeof value || 'function' == typeof value) && 'function' == typeof value.then; | ||
| } | ||
| const isArray = Array.isArray; | ||
| function joinArrays({ customizeArray, customizeObject, key } = {}) { | ||
| return function _joinArrays(a, b, k) { | ||
| const newKey = key ? `${key}.${k}` : k; | ||
| if ('function' == typeof a && 'function' == typeof b) return (...args)=>_joinArrays(a(...args), b(...args), k); | ||
| if (isArray(a) && isArray(b)) { | ||
| const customResult = customizeArray && customizeArray(a, b, newKey); | ||
| return customResult || [ | ||
| ...a, | ||
| ...b | ||
| ]; | ||
| } | ||
| if (isRegex(b)) return b; | ||
| if (isPlainObject(a) && isPlainObject(b)) { | ||
| const customResult = customizeObject && customizeObject(a, b, newKey); | ||
| return customResult || merge_with([ | ||
| a, | ||
| b | ||
| ], joinArrays({ | ||
| customizeArray, | ||
| customizeObject, | ||
| key: newKey | ||
| })); | ||
| } | ||
| if (isPlainObject(b)) return merge_with([ | ||
| {}, | ||
| b | ||
| ], joinArrays({ | ||
| customizeArray, | ||
| customizeObject, | ||
| key: newKey | ||
| })); | ||
| if (isArray(b)) return [ | ||
| ...b | ||
| ]; | ||
| return b; | ||
| }; | ||
| } | ||
| function merge(firstConfiguration, ...configurations) { | ||
| return mergeWithCustomize({})(firstConfiguration, ...configurations); | ||
| } | ||
| function mergeWithCustomize(options) { | ||
| return function(firstConfiguration, ...configurations) { | ||
| if (isUndefined(firstConfiguration) || configurations.some(isUndefined)) throw new TypeError('Merging undefined is not supported'); | ||
| if (isPromiseLike(firstConfiguration)) throw new TypeError('Promises are not supported'); | ||
| if (!firstConfiguration) return {}; | ||
| if (0 === configurations.length) { | ||
| if (Array.isArray(firstConfiguration)) { | ||
| if (0 === firstConfiguration.length) return {}; | ||
| if (firstConfiguration.some(isUndefined)) throw new TypeError('Merging undefined is not supported'); | ||
| if (isPromiseLike(firstConfiguration[0])) throw new TypeError('Promises are not supported'); | ||
| return merge_with(firstConfiguration, joinArrays(options)); | ||
| } | ||
| return firstConfiguration; | ||
| } | ||
| return merge_with([ | ||
| firstConfiguration | ||
| ].concat(configurations), joinArrays(options)); | ||
| }; | ||
| } | ||
| const DEFAULT_EXTENSIONS = [ | ||
@@ -935,7 +1029,9 @@ '.ts', | ||
| const checkIsMultiRspackOptions = (config)=>Array.isArray(config); | ||
| async function loadExtendedConfig(config, configPath, cwd, options) { | ||
| async function loadExtendedConfig(config, configPath, cwd, options, visitedPaths) { | ||
| const currentVisitedPaths = visitedPaths ?? new Set(); | ||
| if (checkIsMultiRspackOptions(config)) { | ||
| const resultPathMap = new WeakMap(); | ||
| const extendedConfigs = await Promise.all(config.map(async (item)=>{ | ||
| const { config, pathMap } = await loadExtendedConfig(item, configPath, cwd, options); | ||
| const itemVisitedPaths = new Set(currentVisitedPaths); | ||
| const { config, pathMap } = await loadExtendedConfig(item, configPath, cwd, options, itemVisitedPaths); | ||
| resultPathMap.set(config, pathMap.get(config)); | ||
@@ -950,2 +1046,4 @@ return config; | ||
| } | ||
| if (currentVisitedPaths.has(configPath)) throw new Error(`Recursive configuration detected. Config file "${configPath}" extends itself.`); | ||
| currentVisitedPaths.add(configPath); | ||
| const pathMap = new WeakMap(); | ||
@@ -970,3 +1068,8 @@ pathMap.set(config, [ | ||
| let resolvedPath; | ||
| if (extendPath.startsWith('.') || extendPath.startsWith('/') || extendPath.includes(':\\')) { | ||
| if (extendPath.startsWith('file://')) try { | ||
| resolvedPath = fileURLToPath(extendPath); | ||
| } catch { | ||
| throw new Error(`Invalid file URL '${extendPath}' in extends configuration.`); | ||
| } | ||
| else if (extendPath.startsWith('.') || extendPath.startsWith('/') || extendPath.includes(':\\')) { | ||
| resolvedPath = node_path.resolve(baseDir, extendPath); | ||
@@ -991,3 +1094,3 @@ if (!node_path.extname(resolvedPath)) { | ||
| const resolvedConfig = await resolveRspackConfigExport(loadedConfig, options); | ||
| const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(resolvedConfig, resolvedPath, cwd, options); | ||
| const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(resolvedConfig, resolvedPath, cwd, options, currentVisitedPaths); | ||
| const configPaths = [ | ||
@@ -997,3 +1100,3 @@ ...pathMap.get(resultConfig) || [], | ||
| ]; | ||
| resultConfig = rspack.util.cleverMerge(extendedConfig, resultConfig); | ||
| resultConfig = merge(extendedConfig, resultConfig); | ||
| pathMap.set(resultConfig, configPaths); | ||
@@ -1054,3 +1157,3 @@ } | ||
| program.help(); | ||
| program.version("2.0.2"); | ||
| program.version("2.0.3"); | ||
| } | ||
@@ -1064,7 +1167,7 @@ wrapAction(fn) { | ||
| async buildCompilerConfig(options, rspackCommand) { | ||
| let { config, pathMap } = await this.loadConfig(options); | ||
| config = await this.buildConfig(config, pathMap, options, rspackCommand); | ||
| const { config: rawConfig, pathMap } = await this.loadConfig(options); | ||
| const config = await this.buildConfig(rawConfig, pathMap, options, rspackCommand); | ||
| return config; | ||
| } | ||
| async createCompiler(config, callback) { | ||
| createCompiler(config, callback) { | ||
| const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch; | ||
@@ -1071,0 +1174,0 @@ let compiler; |
+1
-1
| import node_fs from "node:fs"; | ||
| import node_path from "node:path"; | ||
| import { rspack } from "@rspack/core"; | ||
| const DEFAULT_RUST_TRACE_LAYER = 'perfetto'; | ||
| const DEFAULT_RUST_TRACE_LAYER = 'logger'; | ||
| async function applyProfile(filterValue, traceLayer = DEFAULT_RUST_TRACE_LAYER, traceOutput) { | ||
@@ -6,0 +6,0 @@ const { asyncExitHook } = await import("./exit-hook.js"); |
+5
-4
| { | ||
| "name": "@rspack-debug/cli", | ||
| "version": "2.0.2", | ||
| "version": "2.0.3", | ||
| "description": "CLI for rspack", | ||
@@ -33,3 +33,3 @@ "homepage": "https://rspack.rs", | ||
| "@microsoft/api-extractor": "^7.58.7", | ||
| "@rslib/core": "0.21.3", | ||
| "@rslib/core": "^0.21.4", | ||
| "@rspack/dev-server": "^2.0.1", | ||
@@ -43,5 +43,6 @@ "cac": "^7.0.0", | ||
| "prebundle": "^1.6.4", | ||
| "rspack-merge": "0.1.1", | ||
| "typescript": "^6.0.3", | ||
| "@rspack/core": "npm:@rspack-debug/core@2.0.2", | ||
| "@rspack/test-tools": "npm:@rspack-debug/test-tools@2.0.2" | ||
| "@rspack/core": "npm:@rspack-debug/core@2.0.3", | ||
| "@rspack/test-tools": "npm:@rspack-debug/test-tools@2.0.3" | ||
| }, | ||
@@ -48,0 +49,0 @@ "peerDependencies": { |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 7 instances in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 7 instances in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1761440
0.23%8298
1.26%15
7.14%