You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/11/11 12:40:12 UTC

[cordova-lib] branch master updated: refactor: use execa's cross-platform shebang support in HooksRunner (#819)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-lib.git


The following commit(s) were added to refs/heads/master by this push:
     new 919dfed  refactor: use execa's cross-platform shebang support in HooksRunner (#819)
919dfed is described below

commit 919dfed6b830ec9332ecf00acc15fea411cdca90
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Mon Nov 11 13:40:01 2019 +0100

    refactor: use execa's cross-platform shebang support in HooksRunner (#819)
    
    Up until now, we have maintained code for shebang support in hook
    scripts on Windows. Fortunately, execa comes with support for that out
    of the box. So this commit drops our implementation and makes use of
    execa's.
---
 integration-tests/HooksRunner.spec.js | 14 --------------
 package.json                          |  4 +---
 src/hooks/HooksRunner.js              | 30 ------------------------------
 3 files changed, 1 insertion(+), 47 deletions(-)

diff --git a/integration-tests/HooksRunner.spec.js b/integration-tests/HooksRunner.spec.js
index 24241f0..e29096e 100644
--- a/integration-tests/HooksRunner.spec.js
+++ b/integration-tests/HooksRunner.spec.js
@@ -435,18 +435,4 @@ describe('HooksRunner', function () {
             return hooksRunner.fire('CLEAN YOUR SHORTS GODDAMNIT LIKE A BIG BOY!', hookOptions);
         });
     });
-
-    describe('extractSheBangInterpreter', () => {
-        const rewire = require('rewire');
-        const HooksRunner = rewire('../src/hooks/HooksRunner');
-        const extractSheBangInterpreter = HooksRunner.__get__('extractSheBangInterpreter');
-
-        it('Test 025 : should not read uninitialized buffer contents', () => {
-            spyOn(require('fs'), 'readSync').and.callFake((fd, buf) => {
-                buf.write('#!/usr/bin/env XXX\n# foo');
-                return 0;
-            });
-            expect(extractSheBangInterpreter(__filename)).toBeFalsy();
-        });
-    });
 });
diff --git a/package.json b/package.json
index abac78a..a15d019 100644
--- a/package.json
+++ b/package.json
@@ -31,9 +31,7 @@
     "init-package-json": "^1.10.3",
     "md5-file": "^4.0.0",
     "pify": "^4.0.1",
-    "read-chunk": "^3.2.0",
-    "semver": "^6.3.0",
-    "shebang-command": "^2.0.0"
+    "semver": "^6.3.0"
   },
   "devDependencies": {
     "codecov": "^3.2.0",
diff --git a/src/hooks/HooksRunner.js b/src/hooks/HooksRunner.js
index c89a941..e0e54ec 100644
--- a/src/hooks/HooksRunner.js
+++ b/src/hooks/HooksRunner.js
@@ -17,18 +17,13 @@
 
 const execa = require('execa');
 const fs = require('fs-extra');
-const os = require('os');
 const path = require('path');
-const readChunk = require('read-chunk');
-const shebangCommand = require('shebang-command');
 
 const cordovaUtil = require('../cordova/util');
 const scriptsFinder = require('./scriptsFinder');
 const Context = require('./Context');
 const { CordovaError, events } = require('cordova-common');
 
-const isWindows = os.platform().slice(0, 3) === 'win';
-
 /**
  * Tries to create a HooksRunner for passed project root.
  * @constructor
@@ -173,16 +168,6 @@ function runScriptViaChildProcessSpawn (script, context) {
     var command = script.fullPath;
     var args = [opts.projectRoot];
 
-    if (isWindows) {
-        // TODO: Make shebang sniffing a setting (not everyone will want this).
-        var interpreter = extractSheBangInterpreter(script.fullPath);
-        // we have shebang, so try to run this script using correct interpreter
-        if (interpreter) {
-            args.unshift(command);
-            command = interpreter;
-        }
-    }
-
     const execOpts = {
         cwd: opts.projectRoot,
         stdio: 'inherit',
@@ -202,21 +187,6 @@ function runScriptViaChildProcessSpawn (script, context) {
 }
 
 /**
- * Extracts shebang interpreter from script' source. */
-function extractSheBangInterpreter (fullpath) {
-    // this is a modern cluster size. no need to read less
-    const chunkSize = 4096;
-    const fileData = readChunk.sync(fullpath, 0, chunkSize);
-    const fileChunk = fileData.toString();
-    const hookCmd = shebangCommand(fileChunk);
-
-    if (hookCmd && fileData.length === chunkSize && !fileChunk.match(/[\r\n]/)) {
-        events.emit('warn', 'shebang is too long for "' + fullpath + '"');
-    }
-    return hookCmd;
-}
-
-/**
  * Checks if the given hook type is disabled at the command line option.
  * @param {Object} opts - the option object that contains command line options
  * @param {String} hook - the hook type


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org