From f9bc81760436f4ce90ca1b89b4bb40339537802d Mon Sep 17 00:00:00 2001 From: Robert DeLuca Date: Tue, 30 Apr 2019 16:17:12 -0500 Subject: [PATCH] fix: Introduce cross-spawn for cross platform commands (#175) This PR introduces cross platform spawning of commands. Will close #174. The problem is Windows users need to use the `exec` command like this: ``` $ percy exec -- cypress.cmd run ``` If they don't, we can't spawn their original test command. What's happening is nodes `spawn` ignores windows `PATHEXT` which is kinda like `$PATH` & that means `spawn` only works on Windows for `.exe` files. See: - https://github.com/nodejs/node-v0.x-archive/issues/2318 - https://github.com/bcoe/awesome-cross-platform-nodejs/issues/26 Tested here: https://github.com/percy/example-percy-cypress/compare/rd/test-cross-platform The first commit uses `cross_spawn` and successfully starts Cypress. The second commit uses `0.4.0` of agent and fails to start Cypress. --- package-lock.json | 50 ++++++++++++++++++-------------------------- package.json | 2 ++ src/commands/exec.ts | 2 +- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index a091b3ea..d48c43d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1759,6 +1759,15 @@ "@types/express": "*" } }, + "@types/cross-spawn": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@types/cross-spawn/-/cross-spawn-6.0.0.tgz", + "integrity": "sha512-evp2ZGsFw9YKprDbg8ySgC9NA15g3YgiI8ANkGmKKvvi0P2aDGYLPxQIC5qfeKNUOe3TjABVGuah6omPRpIYhg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/estree": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", @@ -4913,8 +4922,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -4935,14 +4943,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4957,20 +4963,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -5087,8 +5090,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -5100,7 +5102,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5115,7 +5116,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -5123,14 +5123,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -5149,7 +5147,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -5230,8 +5227,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -5243,7 +5239,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -5329,8 +5324,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -5366,7 +5360,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -5386,7 +5379,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5430,14 +5422,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, diff --git a/package.json b/package.json index 57a33a84..2491c042 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "body-parser": "^1.18.3", "colors": "^1.3.2", "cors": "^2.8.4", + "cross-spawn": "^6.0.5", "express": "^4.16.3", "globby": "^9.2.0", "js-yaml": "^3.13.1", @@ -52,6 +53,7 @@ "@types/chai": "^4.1.4", "@types/chai-http": "^3.0.5", "@types/cors": "^2.8.4", + "@types/cross-spawn": "^6.0.0", "@types/http-server": "^0.10.0", "@types/mocha": "^5.2.5", "@types/nock": "^9.3.0", diff --git a/src/commands/exec.ts b/src/commands/exec.ts index dd2dc6d1..0103d5b8 100644 --- a/src/commands/exec.ts +++ b/src/commands/exec.ts @@ -1,5 +1,5 @@ import {flags} from '@oclif/command' -import {spawn} from 'child_process' +import * as spawn from 'cross-spawn' import Constants from '../services/constants' import PercyCommand from './percy-command'