Skip to content

Commit d9e0f8e

Browse files
committed
use updated npx
1 parent cd6f983 commit d9e0f8e

1 file changed

Lines changed: 7 additions & 19 deletions

File tree

skills/cloud-sql-postgres-data/scripts/execute_sql.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,14 @@ function prepareEnvironment() {
9494
function main() {
9595
const { env, userAgent } = prepareEnvironment();
9696
const args = process.argv.slice(2);
97-
const npxArgs = ["--yes", "@toolbox-sdk/server", "--log-level", "error", ...CONFIG_ARGS, "invoke", TOOL_NAME, "--user-agent-metadata", userAgent, ...args];
98-
99-
let command = 'npx';
100-
let spawnArgs = npxArgs;
101-
102-
// The Windows Dependency-Free Bypass
103-
if (os.platform() === 'win32') {
104-
const nodeDir = path.dirname(process.execPath);
105-
const npxCliJs = path.join(nodeDir, 'node_modules', 'npm', 'bin', 'npx-cli.js');
106-
107-
if (fs.existsSync(npxCliJs)) {
108-
command = process.execPath;
109-
spawnArgs = [npxCliJs, ...npxArgs];
110-
} else {
111-
console.error("Error: Could not find the npx executable to launch.");
112-
process.exit(1);
113-
}
114-
}
11597

116-
const child = spawn(command, spawnArgs, { stdio: 'inherit', env });
98+
const command = os.platform() === 'win32' ? 'npx.cmd' : 'npx';
99+
const processedArgs = os.platform() === 'win32' ? args.map(arg => arg.includes('"') ? '"' + arg.replace(/"/g, '""') + '"' : arg) : args;
100+
const npxArgs = ["--yes", "@toolbox-sdk/server@{{.ToolboxVersion}}", "--log-level", "error", ...CONFIG_ARGS, "invoke", TOOL_NAME, "--user-agent-metadata", userAgent, ...processedArgs];
101+
102+
103+
const child = spawn(command, npxArgs, { shell: os.platform() === 'win32', stdio: 'inherit', env });
104+
117105

118106
child.on('close', (code) => {
119107
process.exit(code);

0 commit comments

Comments
 (0)