You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2019/11/21 15:52:31 UTC
[cordova-electron] branch master updated: refator: replace
shelljs/spawn with execa (#118)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-electron.git
The following commit(s) were added to refs/heads/master by this push:
new dd61597 refator: replace shelljs/spawn with execa (#118)
dd61597 is described below
commit dd61597aba3a37753b78cfab4d262c917ef469c0
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Fri Nov 22 00:51:58 2019 +0900
refator: replace shelljs/spawn with execa (#118)
---
bin/templates/cordova/lib/run.js | 4 +-
package-lock.json | 178 +++++++++++++++++-----
package.json | 1 +
tests/spec/unit/create.spec.js | 18 +--
tests/spec/unit/templates/cordova/lib/run.spec.js | 14 +-
5 files changed, 150 insertions(+), 65 deletions(-)
diff --git a/bin/templates/cordova/lib/run.js b/bin/templates/cordova/lib/run.js
index bd597f0..398d47c 100644
--- a/bin/templates/cordova/lib/run.js
+++ b/bin/templates/cordova/lib/run.js
@@ -18,12 +18,12 @@
*/
const electron = require('electron');
-const proc = require('child_process');
+const execa = require('execa');
const path = require('path');
module.exports.run = (args) => {
const pathToMain = path.resolve(__dirname, '..', '..', 'www', 'cdv-electron-main.js');
- const child = proc.spawn(electron, [pathToMain]);
+ const child = execa(electron, [pathToMain]);
child.on('close', (code) => {
process.exit(code);
diff --git a/package-lock.json b/package-lock.json
index 494f310..ff7542e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -392,18 +392,18 @@
}
},
"ansi-escapes": {
- "version": "4.2.1",
- "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.2.1.tgz",
- "integrity": "sha512-Cg3ymMAdN10wOk/VYfLV7KCQyv7EDirJ64500sU7n9UlmioEtDuU5Gd+hj73hXSU/ex7tHJSssmyftDdkMLO8Q==",
+ "version": "4.3.0",
+ "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.0.tgz",
+ "integrity": "sha512-EiYhwo0v255HUL6eDyuLrXEkTi7WwVCLAw+SeOQ7M7qdun1z1pum4DEm/nuqIVbPvi9RPPc9k9LbyBv6H0DwVg==",
"dev": true,
"requires": {
- "type-fest": "^0.5.2"
+ "type-fest": "^0.8.1"
},
"dependencies": {
"type-fest": {
- "version": "0.5.2",
- "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.5.2.tgz",
- "integrity": "sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw==",
+ "version": "0.8.1",
+ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz",
+ "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==",
"dev": true
}
}
@@ -1327,14 +1327,14 @@
}
},
"ejs": {
- "version": "2.7.2",
- "resolved": "https://registry.npmjs.org/ejs/-/ejs-2.7.2.tgz",
- "integrity": "sha512-rHGwtpl67oih3xAHbZlpw5rQAt+YV1mSCu2fUZ9XNrfaGEhom7E+AUiMci+ByP4aSfuAWx7hE0BPuJLMrpXwOw=="
+ "version": "2.7.4",
+ "resolved": "https://registry.npmjs.org/ejs/-/ejs-2.7.4.tgz",
+ "integrity": "sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA=="
},
"electron": {
- "version": "6.1.4",
- "resolved": "https://registry.npmjs.org/electron/-/electron-6.1.4.tgz",
- "integrity": "sha512-QUN59E0dPmkAEYi+OU0jJG6tIAi8VDJpsHLRmdyL62oAuT3+CWJ/gefmNwAWQsIpNj/DieVTn5h+/t/Hke4T+Q==",
+ "version": "6.1.5",
+ "resolved": "https://registry.npmjs.org/electron/-/electron-6.1.5.tgz",
+ "integrity": "sha512-PrdJKkAS0IaSJwu4him03VYqvAKK1qyWTE/ieb4LgcbR4F4u90b91/7xna6P1GpD/FXiHqzZQcs0SvK/o08ckQ==",
"requires": {
"@types/node": "^10.12.18",
"electron-download": "^4.1.0",
@@ -1901,27 +1901,82 @@
"dev": true
},
"execa": {
- "version": "0.7.0",
- "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz",
- "integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=",
- "requires": {
- "cross-spawn": "^5.0.1",
- "get-stream": "^3.0.0",
- "is-stream": "^1.1.0",
- "npm-run-path": "^2.0.0",
- "p-finally": "^1.0.0",
- "signal-exit": "^3.0.0",
- "strip-eof": "^1.0.0"
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/execa/-/execa-3.3.0.tgz",
+ "integrity": "sha512-j5Vit5WZR/cbHlqU97+qcnw9WHRCIL4V1SVe75VcHcD1JRBdt8fv0zw89b7CQHQdUHTt2VjuhcF5ibAgVOxqpg==",
+ "requires": {
+ "cross-spawn": "^7.0.0",
+ "get-stream": "^5.0.0",
+ "human-signals": "^1.1.1",
+ "is-stream": "^2.0.0",
+ "merge-stream": "^2.0.0",
+ "npm-run-path": "^4.0.0",
+ "onetime": "^5.1.0",
+ "p-finally": "^2.0.0",
+ "signal-exit": "^3.0.2",
+ "strip-final-newline": "^2.0.0"
},
"dependencies": {
"cross-spawn": {
+ "version": "7.0.1",
+ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.1.tgz",
+ "integrity": "sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==",
+ "requires": {
+ "path-key": "^3.1.0",
+ "shebang-command": "^2.0.0",
+ "which": "^2.0.1"
+ }
+ },
+ "get-stream": {
"version": "5.1.0",
- "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
- "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=",
+ "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz",
+ "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==",
"requires": {
- "lru-cache": "^4.0.1",
- "shebang-command": "^1.2.0",
- "which": "^1.2.9"
+ "pump": "^3.0.0"
+ }
+ },
+ "is-stream": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz",
+ "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw=="
+ },
+ "npm-run-path": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.0.tgz",
+ "integrity": "sha512-8eyAOAH+bYXFPSnNnKr3J+yoybe8O87Is5rtAQ8qRczJz1ajcsjg8l2oZqP+Ppx15Ii3S1vUTjQN2h4YO2tWWQ==",
+ "requires": {
+ "path-key": "^3.0.0"
+ }
+ },
+ "p-finally": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-2.0.1.tgz",
+ "integrity": "sha512-vpm09aKwq6H9phqRQzecoDpD8TmVyGw70qmWlyq5onxY7tqyTTFVvxMykxQSQKILBSFlbXpypIw2T1Ml7+DDtw=="
+ },
+ "path-key": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.0.tgz",
+ "integrity": "sha512-8cChqz0RP6SHJkMt48FW0A7+qUOn+OsnOsVtzI59tZ8m+5bCSk7hzwET0pulwOM2YMn9J1efb07KB9l9f30SGg=="
+ },
+ "shebang-command": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
+ "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
+ "requires": {
+ "shebang-regex": "^3.0.0"
+ }
+ },
+ "shebang-regex": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
+ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="
+ },
+ "which": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
+ "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
+ "requires": {
+ "isexe": "^2.0.0"
}
}
}
@@ -2333,9 +2388,9 @@
"integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ=="
},
"handlebars": {
- "version": "4.5.2",
- "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.5.2.tgz",
- "integrity": "sha512-29Zxv/cynYB7mkT1rVWQnV7mGX6v7H/miQ6dbEpYTKq5eJBN7PsRB+ViYJlcT6JINTSu4dVB9kOqEun78h6Exg==",
+ "version": "4.5.3",
+ "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.5.3.tgz",
+ "integrity": "sha512-3yPecJoJHK/4c6aZhSvxOyG4vJKDshV36VHp0iVCDVh7o9w2vwi3NSnL2MMPj3YdduqaBcu7cGbggJQM0br9xA==",
"dev": true,
"requires": {
"neo-async": "^2.6.0",
@@ -2381,9 +2436,9 @@
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
},
"has-symbols": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz",
- "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q="
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz",
+ "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg=="
},
"has-yarn": {
"version": "2.1.0",
@@ -2434,6 +2489,11 @@
"sshpk": "^1.7.0"
}
},
+ "human-signals": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-1.1.1.tgz",
+ "integrity": "sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw=="
+ },
"iconv-lite": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.0.tgz",
@@ -2682,11 +2742,11 @@
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
},
"is-symbol": {
- "version": "1.0.2",
- "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz",
- "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==",
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz",
+ "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==",
"requires": {
- "has-symbols": "^1.0.0"
+ "has-symbols": "^1.0.1"
}
},
"is-typedarray": {
@@ -3163,6 +3223,11 @@
"source-map": "^0.6.1"
}
},
+ "merge-stream": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
+ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w=="
+ },
"mime": {
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz",
@@ -3184,8 +3249,7 @@
"mimic-fn": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
- "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==",
- "dev": true
+ "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg=="
},
"mimic-response": {
"version": "1.0.1",
@@ -3586,7 +3650,6 @@
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz",
"integrity": "sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==",
- "dev": true,
"requires": {
"mimic-fn": "^2.1.0"
}
@@ -4818,6 +4881,11 @@
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8="
},
+ "strip-final-newline": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz",
+ "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA=="
+ },
"strip-indent": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-1.0.1.tgz",
@@ -4943,6 +5011,32 @@
"integrity": "sha1-RYuDiH8oj8Vtb/+/rSYuJmOO+mk=",
"requires": {
"execa": "^0.7.0"
+ },
+ "dependencies": {
+ "cross-spawn": {
+ "version": "5.1.0",
+ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
+ "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=",
+ "requires": {
+ "lru-cache": "^4.0.1",
+ "shebang-command": "^1.2.0",
+ "which": "^1.2.9"
+ }
+ },
+ "execa": {
+ "version": "0.7.0",
+ "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz",
+ "integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=",
+ "requires": {
+ "cross-spawn": "^5.0.1",
+ "get-stream": "^3.0.0",
+ "is-stream": "^1.1.0",
+ "npm-run-path": "^2.0.0",
+ "p-finally": "^1.0.0",
+ "signal-exit": "^3.0.0",
+ "strip-eof": "^1.0.0"
+ }
+ }
}
},
"test-exclude": {
diff --git a/package.json b/package.json
index 4eeddc2..219d11c 100644
--- a/package.json
+++ b/package.json
@@ -26,6 +26,7 @@
"cordova-common": "^3.2.0",
"electron": "^6.0.7",
"electron-builder": "^21.2.0",
+ "execa": "^3.3.0",
"fs-extra": "^8.0.1",
"nopt": "^4.0.1",
"shelljs": "^0.5.3"
diff --git a/tests/spec/unit/create.spec.js b/tests/spec/unit/create.spec.js
index aba039b..36d58a9 100644
--- a/tests/spec/unit/create.spec.js
+++ b/tests/spec/unit/create.spec.js
@@ -17,11 +17,10 @@
under the License.
*/
-const shell = require('shelljs');
const fs = require('fs-extra');
const path = require('path');
-const util = require('util');
const rewire = require('rewire');
+const execa = require('execa');
const cordova_bin = path.join(__dirname, '../../../bin');// is this the same on all platforms?
const tmpDir = path.join(__dirname, '../../../temp');
@@ -29,24 +28,17 @@ const createScriptPath = path.join(cordova_bin, 'create');
const create = rewire(path.join(cordova_bin, 'lib', 'create'));
function createAndVerify (projectname, projectid) {
- let return_code = 0;
-
// remove existing folder
fs.removeSync(tmpDir);
fs.ensureDirSync(tmpDir);
- // create the project
- const command = util.format('"%s" "%s/%s" "%s" "%s"', createScriptPath, tmpDir, projectname, projectid, projectname);
-
- return_code = shell.exec(command).code;
- expect(return_code).toBe(0);
-
- var tempCordovaScriptsPath = path.join(tmpDir, projectname, 'cordova');
-
- console.log('tempCordovaScriptsPath = ' + tempCordovaScriptsPath);
+ const tempProjectDir = path.join(tmpDir, projectname);
+ const projectCreateProcess = execa.sync(createScriptPath, [tempProjectDir, projectid, projectname]);
+ expect(projectCreateProcess.exitCode).toBe(0);
// created project has scripts in the cordova folder
// build, clean, log, run, version
+ const tempCordovaScriptsPath = path.join(tempProjectDir, 'cordova');
expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'build'))).toBe(true);
expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'clean'))).toBe(true);
expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'log'))).toBe(true);
diff --git a/tests/spec/unit/templates/cordova/lib/run.spec.js b/tests/spec/unit/templates/cordova/lib/run.spec.js
index b1cb392..1fb853d 100644
--- a/tests/spec/unit/templates/cordova/lib/run.spec.js
+++ b/tests/spec/unit/templates/cordova/lib/run.spec.js
@@ -23,23 +23,21 @@ const run = rewire('../../../../../../bin/templates/cordova/lib/run');
describe('Run', () => {
describe('run export method', () => {
- it('should spawn electron with cdv-electron-main.js.', () => {
- const spawnSpy = jasmine.createSpy('spawn');
+ it('should run electron with cdv-electron-main.js.', () => {
+ const execaSpy = jasmine.createSpy('execa');
const onSpy = jasmine.createSpy('on');
const expectedPathToMain = path.resolve(__dirname, '..', '..', '..', '..', '..', '..', 'bin', 'templates', 'www', 'cdv-electron-main.js');
run.__set__('electron', 'electron-require');
spyOn(process, 'exit');
- run.__set__('proc', {
- spawn: spawnSpy.and.returnValue({
- on: onSpy.and.callThrough()
- })
- });
+ run.__set__('execa', execaSpy.and.returnValue({
+ on: onSpy.and.callThrough()
+ }));
run.run();
- expect(spawnSpy).toHaveBeenCalledWith('electron-require', [expectedPathToMain]);
+ expect(execaSpy).toHaveBeenCalledWith('electron-require', [expectedPathToMain]);
expect(onSpy).toHaveBeenCalled();
expect(process.exit).not.toHaveBeenCalled();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org