@solidstarters/solid-core 1.2.207 → 1.2.208
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/dist/helpers/command.service.d.ts +1 -0
- package/dist/helpers/command.service.d.ts.map +1 -1
- package/dist/helpers/command.service.js +11 -3
- package/dist/helpers/command.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/helpers/command.service.ts +20 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.service.d.ts","sourceRoot":"","sources":["../../src/helpers/command.service.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,qBACa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;
|
|
1
|
+
{"version":3,"file":"command.service.d.ts","sourceRoot":"","sources":["../../src/helpers/command.service.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,qBACa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAM1D,OAAO,CAAC,mBAAmB;IAcrB,sBAAsB,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;CA2ChF"}
|
|
@@ -14,14 +14,22 @@ let CommandService = CommandService_1 = class CommandService {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
this.logger = new common_1.Logger(CommandService_1.name);
|
|
16
16
|
}
|
|
17
|
+
escapeArgForWindows(arg) {
|
|
18
|
+
if (/[{}\s"^&|<>]/.test(arg)) {
|
|
19
|
+
const escaped = arg.replace(/"/g, '\\"');
|
|
20
|
+
return `"${escaped}"`;
|
|
21
|
+
}
|
|
22
|
+
return arg;
|
|
23
|
+
}
|
|
17
24
|
async executeCommandWithArgs(commandWithArgs) {
|
|
18
25
|
const { command, args } = commandWithArgs;
|
|
19
26
|
this.logger.debug(`Executing command: ${command} ${args.join(' ')}`);
|
|
20
27
|
return new Promise((resolve, reject) => {
|
|
21
28
|
const isWindows = process.platform === 'win32';
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
const spawnArgs = isWindows
|
|
30
|
+
? args.map(arg => this.escapeArgForWindows(arg))
|
|
31
|
+
: args;
|
|
32
|
+
const child = (0, child_process_1.spawn)(command, spawnArgs, {
|
|
25
33
|
shell: isWindows,
|
|
26
34
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
27
35
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.service.js","sourceRoot":"","sources":["../../src/helpers/command.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAoD;AACpD,iDAAsC;AAQ/B,IAAM,cAAc,sBAApB,MAAM,cAAc;IAApB;QACY,WAAM,GAAG,IAAI,eAAM,CAAC,gBAAc,CAAC,IAAI,CAAC,CAAC;IA+
|
|
1
|
+
{"version":3,"file":"command.service.js","sourceRoot":"","sources":["../../src/helpers/command.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAoD;AACpD,iDAAsC;AAQ/B,IAAM,cAAc,sBAApB,MAAM,cAAc;IAApB;QACY,WAAM,GAAG,IAAI,eAAM,CAAC,gBAAc,CAAC,IAAI,CAAC,CAAC;IA+D5D,CAAC;IAzDS,mBAAmB,CAAC,GAAW;QAGrC,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAE7B,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YACzC,OAAO,IAAI,OAAO,GAAG,CAAC;QACxB,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAKD,KAAK,CAAC,sBAAsB,CAAC,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AAC;YAChB,CAAC,CAAC,CAAC;YAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBACzB,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;oBACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,IAAI,KAAK,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;oBAC1E,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,iCAAiC,IAAI,EAAE,CAAC,CAAC,CAAC;oBACrE,OAAO;gBACT,CAAC;gBACD,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAhEY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;GACA,cAAc,CAgE1B","sourcesContent":["import { Injectable, Logger } from '@nestjs/common';\nimport { spawn } from 'child_process';\n\nexport type CommandWithArgs = {\n command: string;\n args: string[];\n};\n\n@Injectable()\nexport class CommandService {\n private readonly logger = new Logger(CommandService.name);\n\n /**\n * Escape an argument for Windows CMD shell\n * Wraps in double quotes and escapes internal double quotes\n */\n private escapeArgForWindows(arg: string): string {\n // If arg contains special characters, wrap in double quotes\n // and escape internal double quotes with backslash\n if (/[{}\\s\"^&|<>]/.test(arg)) {\n // Escape internal double quotes with backslash for CMD\n const escaped = arg.replace(/\"/g, '\\\\\"');\n return `\"${escaped}\"`;\n }\n return arg;\n }\n\n /**\n * Execute a command with arguments array (cross-platform compatible)\n */\n async executeCommandWithArgs(commandWithArgs: CommandWithArgs): Promise<string> {\n const { command, args } = commandWithArgs;\n this.logger.debug(`Executing command: ${command} ${args.join(' ')}`);\n\n return new Promise<string>((resolve, reject) => {\n const isWindows = process.platform === 'win32';\n\n // On Windows with shell: true, we need to escape args containing special characters\n const spawnArgs = isWindows\n ? args.map(arg => this.escapeArgForWindows(arg))\n : args;\n\n const child = spawn(command, spawnArgs, {\n shell: isWindows, // Use shell on Windows to handle .cmd files\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n let stdout = '';\n let stderr = '';\n\n child.stdout.on('data', (data) => {\n stdout += data.toString();\n });\n\n child.stderr.on('data', (data) => {\n stderr += data.toString();\n });\n\n child.on('error', (error) => {\n this.logger.error(`Error executing command: ${command}`, error);\n reject(error);\n });\n\n child.on('close', (code) => {\n if (code !== 0) {\n this.logger.error(`Command failed with code ${code}: ${command}`, stderr);\n reject(new Error(stderr || `Command failed with exit code ${code}`));\n return;\n }\n resolve(stdout);\n });\n });\n }\n}\n"]}
|