[Pkg-javascript-commits] [pdf.js] 105/157: Improve getWorkerSrcFiles (builder.js)

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 06:46:44 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 8ba73cb4de7cad6ef080daf741bb6b1ec829f8b1
Author: Rob Wu <rob at robwu.nl>
Date:   Wed Jul 8 20:28:11 2015 +0200

    Improve getWorkerSrcFiles (builder.js)
    
    It took a while to figure out why adding comments in worker_loader.js
    caused the build to fail, because getWorkerSrcFiles did not print an
    error message when it failed to parse the file. These issues have been
    resolved as follows:
    
    - Leading comments are stripped.
    - The trailing comma is removed from the array.
    - Errors are detected and useful error messages are printed.
---
 external/builder/builder.js | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/external/builder/builder.js b/external/builder/builder.js
index c336e43..bc99bc0 100644
--- a/external/builder/builder.js
+++ b/external/builder/builder.js
@@ -235,21 +235,29 @@ function getWorkerSrcFiles(filePath) {
   var src = fs.readFileSync(filePath).toString();
   var reSrcFiles = /var\s+otherFiles\s*=\s*(\[[^\]]*\])/;
   var match = reSrcFiles.exec(src);
+  if (!match) {
+    throw new Error('Cannot find otherFiles array in ' + filePath);
+  }
+
+  var files = match[1].replace(/'/g, '"').replace(/^\s*\/\/.*/gm, '')
+    .replace(/,\s*]$/, ']');
   try {
-    var files = JSON.parse(match[1].replace(/'/g, '"'));
-    var srcFiles = files.filter(function(name) {
-      return name.indexOf('external') === -1;
-    });
-    var externalSrcFiles = files.filter(function(name) {
-      return name.indexOf('external') > -1;
-    });
-    return {
-      srcFiles: srcFiles,
-      externalSrcFiles: externalSrcFiles
-    };
-  } catch(e) {
-    return {};
+    files = JSON.parse(files);
+  } catch (e) {
+    throw new Error('Failed to parse otherFiles in ' + filePath + ' as JSON, ' +
+                    e);
   }
+
+  var srcFiles = files.filter(function(name) {
+    return name.indexOf('external') === -1;
+  });
+  var externalSrcFiles = files.filter(function(name) {
+    return name.indexOf('external') > -1;
+  });
+  return {
+    srcFiles: srcFiles,
+    externalSrcFiles: externalSrcFiles
+  };
 }
 exports.getWorkerSrcFiles = getWorkerSrcFiles;
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list