Skip to content

Commit

Permalink
Replaces RequireJS to SystemJS.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Feb 9, 2017
1 parent 573236e commit fcf059b
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

globals: {
"PDFJSDev": false,
"require": false,
"exports": false,
"SystemJS": false,
},

"rules": {
Expand Down
12 changes: 9 additions & 3 deletions examples/helloworld/hello.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
'use strict';

// In production, the bundled pdf.js shall be used instead of RequireJS.
require.config({paths: {'pdfjs': '../../src'}});
require(['pdfjs/display/api', 'pdfjs/display/global'], function (api, global) {
// In production, the bundled pdf.js shall be used instead of SystemJS.
SystemJS.config({
packages: {'pdfjs': {defaultExtension: 'js'}},
paths: {'pdfjs': '../../src'}
});
Promise.all([SystemJS.import('pdfjs/display/api'),
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.
global.PDFJS.workerSrc = '../../src/worker_loader.js';

Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>

<head>
<script src="../../node_modules/requirejs/require.js"></script>
<script src="../../node_modules/systemjs/dist/system.js"></script>
<script src="hello.js"></script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion examples/svgviewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<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="viewer.js"></script>

<style>
Expand Down
14 changes: 10 additions & 4 deletions examples/svgviewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ function renderDocument(pdf, svgLib) {
}
}

// In production, the bundled pdf.js shall be used instead of RequireJS.
require.config({paths: {'pdfjs': '../../src'}});
require(['pdfjs/display/api', 'pdfjs/display/svg', 'pdfjs/display/global'],
function (api, svg, global) {
// In production, the bundled pdf.js shall be used instead of SystemJS.
SystemJS.config({
packages: {'pdfjs': {defaultExtension: 'js'}},
paths: {'pdfjs': '../../src'}
});
Promise.all([SystemJS.import('pdfjs/display/api'),
SystemJS.import('pdfjs/display/svg'),
SystemJS.import('pdfjs/display/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.
global.PDFJS.workerSrc = '../../src/worker_loader.js';

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"merge-stream": "^1.0.1",
"mkdirp": "^0.5.1",
"node-ensure": "^0.0.0",
"requirejs": "^2.1.22",
"rimraf": "^2.4.1",
"run-sequence": "^1.2.2",
"shelljs": "~0.4.0",
"streamqueue": "^1.1.1",
"systemjs": "^0.20.7",
"typogr": "~0.6.5",
"uglify-js": "^2.6.1",
"wintersmith": "^2.0.0",
Expand Down
19 changes: 15 additions & 4 deletions src/worker_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
})(importScripts);
}

importScripts('../node_modules/requirejs/require.js');
importScripts('../node_modules/systemjs/dist/system.js');

require.config({paths: {'pdfjs': '.'}});
require(['pdfjs/core/network', 'pdfjs/core/worker'],
function (network, worker) {
SystemJS.config({
packages: {
'': {
format: 'amd',
defaultExtension: 'js',
}
},
paths: {
'pdfjs': '.'
}
});

Promise.all([SystemJS.import('pdfjs/core/network'),
SystemJS.import('pdfjs/core/worker')]).then(function () {
// Worker is loaded at this point.
});
2 changes: 1 addition & 1 deletion test/font/font_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<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="../../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="../unit/testreporter.js"></script>
Expand Down
14 changes: 11 additions & 3 deletions test/font/jasmine-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@
'use strict';

function initializePDFJS(callback) {
require.config({paths: {'pdfjs': '../../src'}});
require(['pdfjs/core/fonts', 'pdfjs/core/stream', 'pdfjs/core/primitives',
'pdfjs/core/cmap'], function (fonts, stream, primitives, cmap) {
SystemJS.config({
packages: {'': {defaultExtension: 'js'}},
paths: {'pdfjs': '../../src'}
});
Promise.all([SystemJS.import('pdfjs/core/fonts'),
SystemJS.import('pdfjs/core/stream'),
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.
window.Font = fonts.Font;
window.ToUnicodeMap = fonts.ToUnicodeMap;
Expand Down
18 changes: 12 additions & 6 deletions test/test_slave.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<head>
<title>PDF.js test slave</title>
<meta charset="utf-8">
<script src="../node_modules/requirejs/require.js"></script>
<script src="../node_modules/systemjs/dist/system.js"></script>
<script src="driver.js"></script>
</head>
<body>
Expand All @@ -31,11 +31,17 @@
<div id="end"></div>
</body>
<script>
require.config({paths: {'pdfjs': '../src'}});
require(['pdfjs/display/api', 'pdfjs/display/text_layer',
'pdfjs/display/annotation_layer', 'pdfjs/display/global',
'pdfjs/shared/util'],
function (api, textLayer, annotationLayer, global, pdfjsSharedUtil) {
SystemJS.config({
packages: {'pdfjs': {defaultExtension: 'js'}},
paths: {'pdfjs': '../src'}
});
Promise.all([SystemJS.import('pdfjs/display/api'),
SystemJS.import('pdfjs/display/text_layer'),
SystemJS.import('pdfjs/display/annotation_layer'),
SystemJS.import('pdfjs/display/global'),
SystemJS.import('pdfjs/shared/util')])
.then(function (modules) {
var pdfjsSharedUtil = modules[4];
window.pdfjsSharedUtil = pdfjsSharedUtil;

var driver = new Driver({
Expand Down
28 changes: 16 additions & 12 deletions test/unit/jasmine-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@
'use strict';

function initializePDFJS(callback) {
require.config({paths: {'pdfjs': '../../src', 'pdfjs-web': '../../web',
'pdfjs-test': '..'}});
require(['pdfjs/display/global', 'pdfjs-test/unit/annotation_spec',
SystemJS.config({
packages: {'': {defaultExtension: 'js'}},
paths: {
'pdfjs': '../../src',
'pdfjs-web': '../../web',
'pdfjs-test': '..'
}
});
Promise.all([
'pdfjs/display/global', 'pdfjs-test/unit/annotation_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/crypto_spec', 'pdfjs-test/unit/document_spec',
Expand All @@ -54,15 +61,12 @@ function initializePDFJS(callback) {
'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/unicode_spec',
'pdfjs-test/unit/util_spec'],
function (displayGlobal, testUnitAnnotationSpec, testUnitApiSpec,
testUnitBidiSpec, testUnitCFFParserSpec, testUnitCMapSpec,
testUnitCryptoSpec, testUnitDocumentSpec, testUnitDOMUtilsSpec,
testUnitEvaluatorSpec, testUnitFontsSpec, testUnitFunctionSpec,
testUnitMetadataSpec, testUnitMurmurHash3Spec,
testUnitNetworkSpec, testUnitParserSpec, testUnitPrimitivesSpec,
testUnitStreamSpec, testUnitType1ParserSpec, testUnitUiUtilsSpec,
testUnitUnicodeSpec, testUnitUtilSpec) {
'pdfjs-test/unit/util_spec'
].map(function (moduleName) {
return SystemJS.import(moduleName);
}))
.then(function (modules) {
var displayGlobal = modules[0];

// Configure the worker.
displayGlobal.PDFJS.workerSrc = '../../src/worker_loader.js';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/unit_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<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="../../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="testreporter.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<!--#endif-->

<!--#if !PRODUCTION-->
<script src="../node_modules/requirejs/require.js"></script>
<script src="../node_modules/systemjs/dist/system.js"></script>
<!--#endif-->

<!--#if (GENERIC && !MINIFIED) -->
Expand Down
18 changes: 16 additions & 2 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,22 @@ function getViewerConfiguration() {
function webViewerLoad() {
var config = getViewerConfiguration();
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
require.config({paths: {'pdfjs': '../src', 'pdfjs-web': '.'}});
require(['pdfjs-web/app', 'pdfjs-web/pdf_print_service'], function (web) {
SystemJS.config({
packages: {
'': {
format: 'amd',
defaultExtension: 'js',
}
},
paths: {
'pdfjs': '../src',
'pdfjs-web': '.'
}
});
Promise.all([SystemJS.import('pdfjs-web/app'),
SystemJS.import('pdfjs-web/pdf_print_service')])
.then(function (modules) {
var web = modules[0];
window.PDFViewerApplication = web.PDFViewerApplication;
web.PDFViewerApplication.run(config);
});
Expand Down

0 comments on commit fcf059b

Please sign in to comment.