Merge pull request #8050 from yurydelendik/systemjs

Replaces RequireJS to SystemJS.
This commit is contained in:
Tim van der Meij 2017-02-27 23:31:41 +01:00 committed by GitHub
commit 25f772a255
15 changed files with 118 additions and 64 deletions

View File

@ -12,8 +12,8 @@
globals: { globals: {
"PDFJSDev": false, "PDFJSDev": false,
"require": false,
"exports": false, "exports": false,
"SystemJS": false,
}, },
"rules": { "rules": {

View File

@ -1,8 +1,10 @@
'use strict'; 'use strict';
// In production, the bundled pdf.js shall be used instead of RequireJS. // In production, the bundled pdf.js shall be used instead of SystemJS.
require.config({paths: {'pdfjs': '../../src'}}); Promise.all([SystemJS.import('pdfjs/display/api'),
require(['pdfjs/display/api', 'pdfjs/display/global'], function (api, global) { SystemJS.import('pdfjs/display/global')])
.then(function (modules) {
var api = modules[0], global = modules[1];
// In production, change this to point to the built `pdf.worker.js` file. // In production, change this to point to the built `pdf.worker.js` file.
global.PDFJS.workerSrc = '../../src/worker_loader.js'; global.PDFJS.workerSrc = '../../src/worker_loader.js';

View File

@ -2,7 +2,8 @@
<html> <html>
<head> <head>
<script src="../../node_modules/requirejs/require.js"></script> <script src="../../node_modules/systemjs/dist/system.js"></script>
<script src="../../systemjs.config.js"></script>
<script src="hello.js"></script> <script src="hello.js"></script>
</head> </head>

View File

@ -6,7 +6,8 @@
<title>PDF.js SVG viewer example</title> <title>PDF.js SVG viewer example</title>
<script src="../../node_modules/requirejs/require.js"></script> <script src="../../node_modules/systemjs/dist/system.js"></script>
<script src="../../systemjs.config.js"></script>
<script src="viewer.js"></script> <script src="viewer.js"></script>
<style> <style>

View File

@ -36,10 +36,11 @@ function renderDocument(pdf, svgLib) {
} }
} }
// In production, the bundled pdf.js shall be used instead of RequireJS. Promise.all([SystemJS.import('pdfjs/display/api'),
require.config({paths: {'pdfjs': '../../src'}}); SystemJS.import('pdfjs/display/svg'),
require(['pdfjs/display/api', 'pdfjs/display/svg', 'pdfjs/display/global'], SystemJS.import('pdfjs/display/global')])
function (api, svg, global) { .then(function (modules) {
var api = modules[0], svg = modules[1], global = modules[2];
// In production, change this to point to the built `pdf.worker.js` file. // In production, change this to point to the built `pdf.worker.js` file.
global.PDFJS.workerSrc = '../../src/worker_loader.js'; global.PDFJS.workerSrc = '../../src/worker_loader.js';

View File

@ -16,11 +16,11 @@
"merge-stream": "^1.0.1", "merge-stream": "^1.0.1",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"node-ensure": "^0.0.0", "node-ensure": "^0.0.0",
"requirejs": "^2.1.22",
"rimraf": "^2.4.1", "rimraf": "^2.4.1",
"run-sequence": "^1.2.2", "run-sequence": "^1.2.2",
"shelljs": "~0.4.0", "shelljs": "~0.4.0",
"streamqueue": "^1.1.1", "streamqueue": "^1.1.1",
"systemjs": "^0.20.7",
"typogr": "~0.6.5", "typogr": "~0.6.5",
"uglify-js": "^2.6.1", "uglify-js": "^2.6.1",
"webpack": "^2.2.1", "webpack": "^2.2.1",

View File

@ -15,21 +15,20 @@
'use strict'; 'use strict';
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) { // Patch importScripts to work around a bug in WebKit and Chrome 48-.
// Patch importScripts to work around a bug in WebKit and Chrome 48-. // See https://crbug.com/572225 and https://webkit.org/b/153317.
// See https://crbug.com/572225 and https://webkit.org/b/153317. self.importScripts = (function (importScripts) {
self.importScripts = (function (importScripts) { return function() {
return function() { setTimeout(function () {}, 0);
setTimeout(function () {}, 0); return importScripts.apply(this, arguments);
return importScripts.apply(this, arguments); };
}; })(importScripts);
})(importScripts);
}
importScripts('../node_modules/requirejs/require.js'); importScripts('./shared/compatibility.js');
importScripts('../node_modules/systemjs/dist/system.js');
importScripts('../systemjs.config.js');
require.config({paths: {'pdfjs': '.'}}); Promise.all([SystemJS.import('pdfjs/core/network'),
require(['pdfjs/core/network', 'pdfjs/core/worker'], SystemJS.import('pdfjs/core/worker')]).then(function () {
function (network, worker) {
// Worker is loaded at this point. // Worker is loaded at this point.
}); });

45
systemjs.config.js Normal file
View File

@ -0,0 +1,45 @@
/* Copyright 2017 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
(function () {
var baseLocation;
if (typeof document !== 'undefined') {
baseLocation = new URL('./', document.currentScript.src);
} else if (typeof location !== 'undefined') {
// Probably worker -- walking subfolders until we will reach root.
baseLocation = location;
while (baseLocation.href.includes('/src/')) {
baseLocation = new URL('..', baseLocation);
}
} else {
throw new Error('Cannot configure SystemJS');
}
SystemJS.config({
packages: {
'': {
format: 'amd',
defaultExtension: 'js',
}
},
paths: {
'pdfjs': new URL('src', baseLocation).href,
'pdfjs-web': new URL('web', baseLocation).href,
'pdfjs-test': new URL('test', baseLocation).href,
}
});
})();

View File

@ -5,7 +5,8 @@
<link rel="stylesheet" type="text/css" href="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css"> <link rel="stylesheet" type="text/css" href="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<script src="../../node_modules/requirejs/require.js"></script> <script src="../../node_modules/systemjs/dist/system.js"></script>
<script src="../../systemjs.config.js"></script>
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script> <script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script> <script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="../unit/testreporter.js"></script> <script src="../unit/testreporter.js"></script>

View File

@ -41,9 +41,13 @@
'use strict'; 'use strict';
function initializePDFJS(callback) { function initializePDFJS(callback) {
require.config({paths: {'pdfjs': '../../src'}}); Promise.all([SystemJS.import('pdfjs/core/fonts'),
require(['pdfjs/core/fonts', 'pdfjs/core/stream', 'pdfjs/core/primitives', SystemJS.import('pdfjs/core/stream'),
'pdfjs/core/cmap'], function (fonts, stream, primitives, cmap) { SystemJS.import('pdfjs/core/primitives'),
SystemJS.import('pdfjs/core/cmap')])
.then(function (modules) {
var fonts = modules[0], stream = modules[1],
primitives = modules[2], cmap = modules[3];
// Expose some of the PDFJS members to global scope for tests. // Expose some of the PDFJS members to global scope for tests.
window.Font = fonts.Font; window.Font = fonts.Font;
window.ToUnicodeMap = fonts.ToUnicodeMap; window.ToUnicodeMap = fonts.ToUnicodeMap;

View File

@ -18,7 +18,8 @@ limitations under the License.
<head> <head>
<title>PDF.js test slave</title> <title>PDF.js test slave</title>
<meta charset="utf-8"> <meta charset="utf-8">
<script src="../node_modules/requirejs/require.js"></script> <script src="../node_modules/systemjs/dist/system.js"></script>
<script src="../systemjs.config.js"></script>
<script src="driver.js"></script> <script src="driver.js"></script>
</head> </head>
<body> <body>
@ -31,12 +32,13 @@ limitations under the License.
<div id="end"></div> <div id="end"></div>
</body> </body>
<script> <script>
require.config({paths: {'pdfjs': '../src'}}); Promise.all([SystemJS.import('pdfjs/display/api'),
require(['pdfjs/display/api', 'pdfjs/display/text_layer', SystemJS.import('pdfjs/display/text_layer'),
'pdfjs/display/annotation_layer', 'pdfjs/display/global', SystemJS.import('pdfjs/display/annotation_layer'),
'pdfjs/shared/util'], SystemJS.import('pdfjs/display/global'),
function (api, textLayer, annotationLayer, global, pdfjsSharedUtil) { SystemJS.import('pdfjs/shared/util')])
window.pdfjsSharedUtil = pdfjsSharedUtil; .then(function (modules) {
window.pdfjsSharedUtil = modules[4];
var driver = new Driver({ var driver = new Driver({
disableScrolling: document.getElementById('disableScrolling'), disableScrolling: document.getElementById('disableScrolling'),

View File

@ -41,28 +41,22 @@
'use strict'; 'use strict';
function initializePDFJS(callback) { function initializePDFJS(callback) {
require.config({paths: {'pdfjs': '../../src', 'pdfjs-web': '../../web', Promise.all([
'pdfjs-test': '..'}}); 'pdfjs/display/global', 'pdfjs-test/unit/annotation_spec',
require(['pdfjs/display/global', 'pdfjs-test/unit/annotation_spec', 'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/bidi_spec',
'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/bidi_spec', 'pdfjs-test/unit/cff_parser_spec', 'pdfjs-test/unit/cmap_spec',
'pdfjs-test/unit/cff_parser_spec', 'pdfjs-test/unit/cmap_spec', 'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/document_spec',
'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/document_spec', 'pdfjs-test/unit/dom_utils_spec', 'pdfjs-test/unit/evaluator_spec',
'pdfjs-test/unit/dom_utils_spec', 'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/fonts_spec', 'pdfjs-test/unit/function_spec',
'pdfjs-test/unit/fonts_spec', 'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec',
'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/parser_spec',
'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec',
'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec', 'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/ui_utils_spec',
'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/unicode_spec', 'pdfjs-test/unit/util_spec'
'pdfjs-test/unit/ui_utils_spec', 'pdfjs-test/unit/unicode_spec', ].map(function (moduleName) {
'pdfjs-test/unit/util_spec'], return SystemJS.import(moduleName);
function (displayGlobal, testUnitAnnotationSpec, testUnitApiSpec, })).then(function (modules) {
testUnitBidiSpec, testUnitCFFParserSpec, testUnitCMapSpec, var displayGlobal = modules[0];
testUnitCryptoSpec, testUnitDocumentSpec, testUnitDOMUtilsSpec,
testUnitEvaluatorSpec, testUnitFontsSpec, testUnitFunctionSpec,
testUnitMetadataSpec, testUnitMurmurHash3Spec,
testUnitNetworkSpec, testUnitParserSpec, testUnitPrimitivesSpec,
testUnitStreamSpec, testUnitType1ParserSpec, testUnitUiUtilsSpec,
testUnitUnicodeSpec, testUnitUtilSpec) {
// Configure the worker. // Configure the worker.
displayGlobal.PDFJS.workerSrc = '../../src/worker_loader.js'; displayGlobal.PDFJS.workerSrc = '../../src/worker_loader.js';

View File

@ -5,7 +5,8 @@
<link rel="stylesheet" type="text/css" href="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css"> <link rel="stylesheet" type="text/css" href="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<script src="../../node_modules/requirejs/require.js"></script> <script src="../../node_modules/systemjs/dist/system.js"></script>
<script src="../../systemjs.config.js"></script>
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script> <script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script> <script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="testreporter.js"></script> <script src="testreporter.js"></script>

View File

@ -53,7 +53,8 @@ See https://github.com/adobe-type-tools/cmap-resources
<!--#endif--> <!--#endif-->
<!--#if !PRODUCTION--> <!--#if !PRODUCTION-->
<script src="../node_modules/requirejs/require.js"></script> <script src="../node_modules/systemjs/dist/system.js"></script>
<script src="../systemjs.config.js"></script>
<!--#endif--> <!--#endif-->
<!--#if (GENERIC && !MINIFIED) --> <!--#if (GENERIC && !MINIFIED) -->

View File

@ -171,10 +171,12 @@ function getViewerConfiguration() {
function webViewerLoad() { function webViewerLoad() {
var config = getViewerConfiguration(); var config = getViewerConfiguration();
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) { if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
require.config({paths: {'pdfjs': '../src', 'pdfjs-web': '.'}}); Promise.all([SystemJS.import('pdfjs-web/app'),
require(['pdfjs-web/app', 'pdfjs-web/pdf_print_service'], function (web) { SystemJS.import('pdfjs-web/pdf_print_service')])
window.PDFViewerApplication = web.PDFViewerApplication; .then(function (modules) {
web.PDFViewerApplication.run(config); var app = modules[0];
window.PDFViewerApplication = app.PDFViewerApplication;
app.PDFViewerApplication.run(config);
}); });
} else { } else {
window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication; window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;