Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to conditions that pdfjsLib #8154

Merged
merged 1 commit into from
Mar 13, 2017

Conversation

mysterlune
Copy link
Contributor

Changing the order of logical conditions to prefer in the case where webpack is not used.

In the case where webpack is not being used (presumably in a server-side require context) for the distribution, the case which uses require presumes that the require implementation can use a relative path to find the module.

However, the ../build/pdf.js file may not be available to require as expected. The value set on window is certainly available in this case. So my thinking here is to prefer the window value for setting pdfjsLib where it is available and fall back to require if doing the rendering on the server-side (where require will be more free to find the pdf.js module by relative path).

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As asked for in #8146 (comment), did you test this patch with https://github.com/mozilla/pdf.js/tree/master/examples/webpack to ensure that the example still works?

web/pdfjs.js Outdated
if (typeof window !== 'undefined' && window['pdfjs-dist/build/pdf']) {
pdfjsLib = window['pdfjs-dist/build/pdf'];
}
else if (typeof require === 'function') {
Copy link
Collaborator

@Snuffleupagus Snuffleupagus Mar 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see in https://travis-ci.org/mozilla/pdf.js/builds/210076791#L501, this causes ESLint failures. Please note that the coding style calls for } and else to be placed on the same line, i.e. } else if (...) { (and similar below).

web/pdfjs.js Outdated
pdfjsLib = require('../build/pdf.js');
}
else {
throw 'Neither `require` nor `window` found';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Please use throw new Error(...) instead.

@mysterlune
Copy link
Contributor Author

@Snuffleupagus, yes. just posted to the issue the following info:

i've run the unit tests for the project and see that:

Run 788 tests
All unit tests passed.
unit tests runtime was 26.9 seconds
[13:50:04] Finished 'unittest' after 28 s

... next, i built the webpack bundles:

13:54 rlune@oakm111430f01:~/gitproj/pdf.js/examples/webpack $ node_modules/.bin/webpack 
Hash: 8a854da8c214c32443b1
Version: webpack 1.12.15
Time: 23259ms
Asset                 Size           Chunks             Chunk Names
main.bundle.js        163 kB           0    [emitted]    main
1.1.bundle.js         603 kB           1    [emitted]  
pdf.worker.bundle.js  605 kB           2, 1 [emitted]    pdf.worker
[0] ./main.js         1.17 kB {0}           [built]
+ 4 hidden modules

... then fired up the example webpack as you suggested. in the browser, here's what i see...

https://cl.ly/jVnD

web/pdfjs.js Outdated
} else {
pdfjsLib = window['pdfjs-dist/build/pdf']; // loaded via html script tag
throw 'Neither `require` nor `window` found';
Copy link
Collaborator

@Snuffleupagus Snuffleupagus Mar 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As previously mentioned, please change this to throw new Error(...); instead.
Also, once you've made the changes, please squash the commits into one such that this is ready for review (see https://github.com/mozilla/pdf.js/wiki/Squashing-Commits for more on this matter).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops. sure thing ;)

…se where webpack is not used.

Updating brace style.

Updating to throw new error vs. throwing a string.
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/ff4514644457073/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/ff4514644457073/output.txt

Total script time: 2.14 mins

Published

@yurydelendik
Copy link
Contributor

Looks good. Thank you for the patch.

@yurydelendik yurydelendik merged commit 2b17188 into mozilla:master Mar 13, 2017
@timvandermeij timvandermeij removed the request for review from yurydelendik March 13, 2017 22:18
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants