[Pkg-javascript-commits] [pdf.js] 57/414: Adds UMD header to pdf.js and pdf.worker.js files.

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:05 UTC 2016


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

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

commit cbbb9bb82de263c9ec25451b9d73af34e3e588bf
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Wed Dec 23 17:46:08 2015 -0600

    Adds UMD header to pdf.js and pdf.worker.js files.
---
 external/umdutils/verifier.js |  3 +++
 make.js                       | 20 ++++++++++++----
 src/display/api.js            | 20 ++++++++++++----
 src/frameworks.js             | 13 +++++++---
 src/pdf.js                    | 55 +++++++++++++++++++++----------------------
 src/shared/global.js          |  9 ++++++-
 6 files changed, 79 insertions(+), 41 deletions(-)

diff --git a/external/umdutils/verifier.js b/external/umdutils/verifier.js
index 8647390..1e3fd5b 100644
--- a/external/umdutils/verifier.js
+++ b/external/umdutils/verifier.js
@@ -55,6 +55,9 @@ var path = require('path');
  */
 function parseUmd(filePath) {
   var jscode = fs.readFileSync(filePath).toString();
+  if (/\/\*\s*umdutils\s+ignore\s*\*\//.test(jscode)) {
+    throw new Error('UMD processing ignored');
+  }
   // Extracts header and body.
   var umdStart = '\\(function\\s\\(root,\\sfactory\\)\\s\\{';
   var umdImports = '\\}\\(this,\\sfunction\\s\\(exports\\b';
diff --git a/make.js b/make.js
index c544cca..3423d0b 100644
--- a/make.js
+++ b/make.js
@@ -484,7 +484,7 @@ target.bundle = function(args) {
   echo();
   echo('### Bundling files into ' + BUILD_TARGET);
 
-  function bundle(filename, outfilename, files) {
+  function bundle(filename, outfilename, files, distname) {
     var bundleContent = cat(files),
         bundleVersion = VERSION,
         bundleBuild = exec('git log --format="%h" -n 1',
@@ -500,12 +500,18 @@ target.bundle = function(args) {
     // Removes AMD and CommonJS branches from UMD headers.
     bundleContent = stripUMDHeaders(bundleContent);
 
+    var amdName = 'pdfjs-dist/build/' + distname.replace(/\.js$/, '');
+    var jsName = amdName.replace(/[\-_\.\/]\w/g, function (all) {
+      return all[1].toUpperCase();
+    });
     // This just preprocesses the empty pdf.js file, we don't actually want to
     // preprocess everything yet since other build targets use this file.
     builder.preprocess(filename, outfilename, builder.merge(defines,
                            {BUNDLE: bundleContent,
                             BUNDLE_VERSION: bundleVersion,
-                            BUNDLE_BUILD: bundleBuild}));
+                            BUNDLE_BUILD: bundleBuild,
+                            BUNDLE_AMD_NAME: amdName,
+                            BUNDLE_JS_NAME: jsName}));
   }
 
   if (!test('-d', BUILD_DIR)) {
@@ -524,6 +530,9 @@ target.bundle = function(args) {
     SRC_DIR + 'core/worker.js'
   ];
 
+  var mainFileName = 'pdf.js';
+  var workerFileName = 'pdf.worker.js';
+
   // Extension does not need svg.js and network.js files.
   if (!defines.FIREFOX && !defines.MOZCENTRAL) {
     MAIN_SRC_FILES.push(SRC_DIR + 'display/svg.js');
@@ -535,6 +544,8 @@ target.bundle = function(args) {
     // the main pdf.js output.
     MAIN_SRC_FILES = MAIN_SRC_FILES.concat(WORKER_SRC_FILES);
     WORKER_SRC_FILES = null; // no need for worker file
+    mainFileName = 'pdf.combined.js';
+    workerFileName = null;
   }
 
   // Reading UMD headers and building loading orders of modules. The
@@ -549,12 +560,13 @@ target.bundle = function(args) {
 
   cd(SRC_DIR);
 
-  bundle('pdf.js', ROOT_DIR + BUILD_TARGET, mainFiles);
+  bundle('pdf.js', ROOT_DIR + BUILD_TARGET, mainFiles, mainFileName);
 
   if (workerFiles) {
     var srcCopy = ROOT_DIR + BUILD_DIR + 'pdf.worker.js.temp';
     cp('pdf.js', srcCopy);
-    bundle(srcCopy, ROOT_DIR + BUILD_WORKER_TARGET, workerFiles);
+    bundle(srcCopy, ROOT_DIR + BUILD_WORKER_TARGET, workerFiles,
+           workerFileName);
     rm(srcCopy);
   }
 };
diff --git a/src/display/api.js b/src/display/api.js
index bfa7b40..6a01c50 100644
--- a/src/display/api.js
+++ b/src/display/api.js
@@ -12,6 +12,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+/* globals pdfjsFilePath */
 
 'use strict';
 
@@ -1177,6 +1178,18 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
 var PDFWorker = (function PDFWorkerClosure() {
   var nextFakeWorkerId = 0;
 
+  function getWorkerSrc() {
+    if (PDFJS.workerSrc) {
+      return PDFJS.workerSrc;
+    }
+//#if PRODUCTION && !(MOZCENTRAL || FIREFOX)
+//  if (pdfjsFilePath) {
+//    return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
+//  }
+//#endif
+    error('No PDFJS.workerSrc specified');
+  }
+
   // Loads worker code into main thread.
   function setupFakeWorkerGlobal() {
     if (!PDFJS.fakeWorkerFilesLoadedCapability) {
@@ -1201,7 +1214,7 @@ var PDFWorker = (function PDFWorkerClosure() {
 //#endif
 //#if PRODUCTION && !SINGLE_FILE
 //    var loader = fakeWorkerFilesLoader || function (callback) {
-//      Util.loadScript(PDFJS.workerSrc, callback);
+//      Util.loadScript(getWorkerSrc(), callback);
 //    };
 //    loader(function () {
 //      PDFJS.fakeWorkerFilesLoadedCapability.resolve();
@@ -1243,10 +1256,7 @@ var PDFWorker = (function PDFWorkerClosure() {
       // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
 //#if !SINGLE_FILE
       if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') {
-        var workerSrc = PDFJS.workerSrc;
-        if (!workerSrc) {
-          error('No PDFJS.workerSrc specified');
-        }
+        var workerSrc = getWorkerSrc();
 
         try {
           // Some versions of FF can't create a worker on localhost, see:
diff --git a/src/frameworks.js b/src/frameworks.js
index 33e34ce..95b4d36 100644
--- a/src/frameworks.js
+++ b/src/frameworks.js
@@ -12,7 +12,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS, require, module */
+/* globals PDFJS, require, module, requirejs */
 
 // included from api.js for GENERIC build
 
@@ -32,9 +32,16 @@ if (typeof __webpack_require__ !== 'undefined') {
   PDFJS.workerSrc = require('entry?name=[hash]-worker.js!./pdf.worker.js');
   useRequireEnsure = true;
 }
-var fakeWorkerFilesLoader = useRequireEnsure && function (callback) {
+if (typeof requirejs !== 'undefined' && requirejs.toUrl) {
+  PDFJS.workerSrc = requirejs.toUrl('pdfjs-dist/build/pdf.worker.js');
+}
+var fakeWorkerFilesLoader = useRequireEnsure ? (function (callback) {
   require.ensure([], function () {
     require('./pdf.worker.js');
     callback();
   });
-};
+}) : (typeof requirejs !== 'undefined') ? (function (callback) {
+  requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) {
+    callback();
+  });
+}) : null;
diff --git a/src/pdf.js b/src/pdf.js
index e9e9b6c..c5276e5 100644
--- a/src/pdf.js
+++ b/src/pdf.js
@@ -13,36 +13,35 @@
  * limitations under the License.
  */
 /* jshint globalstrict: false */
-/* globals PDFJS, global */
-
-// Initializing PDFJS global object (if still undefined)
-if (typeof PDFJS === 'undefined') {
-  (typeof window !== 'undefined' ? window :
-   typeof global !== 'undefined' ? global : this).PDFJS = {};
-}
-
-//#if BUNDLE_VERSION
-//#expand PDFJS.version = '__BUNDLE_VERSION__';
-//#endif
-//#if BUNDLE_BUILD
-//#expand PDFJS.build = '__BUNDLE_BUILD__';
-//#endif
-
-(function pdfjsWrapper() {
+/* umdutils ignore */
+
+(function (root, factory) {
+  'use strict';
+  if (typeof define === 'function' && define.amd) {
+//#expand define('__BUNDLE_AMD_NAME__', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+//#expand factory((root.__BUNDLE_JS_NAME__ = {}));
+  }
+}(this, function (exports) {
   // Use strict in our context only - users might not want it
   'use strict';
 
+//#expand var pdfjsVersion = '__BUNDLE_VERSION__';
+//#expand var pdfjsBuild = '__BUNDLE_BUILD__';
+
+  var pdfjsFilePath =
+    typeof document !== 'undefined' && document.currentScript ?
+      document.currentScript.src : null;
+
+  var pdfjsLibs = {};
+
+  (function pdfjsWrapper() {
+
 //#expand __BUNDLE__
 
-}).call((typeof window === 'undefined') ? this : window);
-
-//#if !(MOZCENTRAL || FIREFOX)
-if (!PDFJS.workerSrc && typeof document !== 'undefined') {
-  // workerSrc is not set -- using last script url to define default location
-  PDFJS.workerSrc = (function () {
-    'use strict';
-    var pdfJsSrc = document.currentScript.src;
-    return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
-  })();
-}
-//#endif
+  }).call(pdfjsLibs);
+
+  exports.PDFJS = pdfjsLibs.pdfjsSharedGlobal.PDFJS;
+}));
diff --git a/src/shared/global.js b/src/shared/global.js
index 219afe3..94b8ef9 100644
--- a/src/shared/global.js
+++ b/src/shared/global.js
@@ -12,7 +12,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals global */
+/* globals global, pdfjsVersion, pdfjsBuild */
 
 'use strict';
 
@@ -39,6 +39,13 @@
     globalScope.PDFJS = {};
   }
 
+  if (typeof pdfjsVersion !== 'undefined') {
+    globalScope.PDFJS.version = pdfjsVersion;
+  }
+  if (typeof pdfjsVersion !== 'undefined') {
+    globalScope.PDFJS.build = pdfjsBuild;
+  }
+
   globalScope.PDFJS.pdfBug = false;
 
   exports.globalScope = globalScope;

-- 
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