-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Adds UMD headers to core, display and shared files. #6683
Conversation
After this patch you can execute the following in the node.js:
|
6f6787c
to
513b9f9
Compare
Questions:
|
The validation of the names is done by
Yes. The intent will be eventually to build without UMD headers -- those can be replaced by regular function closure, e.g.
where root can be some local object instead of window. Also, I think we shall remove all links to core/display/shared files and use module loaders instead (e.g. RequireJS). (IHMO it's out of scope of this PR ATM -- I don't want to touch our build system without real need to) |
Let me also re-iterate how to choose names:
|
@@ -542,3 +593,7 @@ var PDFDocument = (function PDFDocumentClosure() { | |||
|
|||
return PDFDocument; | |||
})(); | |||
|
|||
exports.Paga = Page; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: typo exports.Paga
should be exports.Page
.
A testing related nit: shouldn't |
513b9f9
to
529b5e1
Compare
Aside from the nit above, this PR needs a rebase too after the recently landed PRs. |
663db97
to
1c71074
Compare
@yurydelendik Could you rebase this PR again? I think we should land this soon as it keeps on needing a rebase and it looks good to have modules and to drop most of the globals. |
1c71074
to
eafe35f
Compare
/botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/397b69541371361/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/397b69541371361/output.txt Total script time: 0.79 mins Published |
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.22.172.223:8877/a8be5c2601c97ae/output.txt |
From: Bot.io (Linux)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/1d5e50d933793ce/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/a8be5c2601c97ae/output.txt Total script time: 19.04 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/1d5e50d933793ce/output.txt Total script time: 20.31 mins
|
ca1dd1b
to
d804ac0
Compare
d804ac0
to
2898e31
Compare
New 'evaluator' on 'function' dependency is added by #6723 -- fixed. |
exports.PDFFunction = PDFFunction; | ||
exports.PostScriptEvaluator = PostScriptEvaluator; | ||
exports.PostScriptCompiler = PostScriptCompiler; | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you also need to export isPDFFunction
here, or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, node make lint
was throwing "ERROR:The non-exported symbol is referred: isPDFFunction from pdfjs/core/function used in pdfjs/core/evaluator". I think we need to change travis to execute that instead.
2898e31
to
ebf1df0
Compare
ebf1df0
to
bd9e17d
Compare
context.warnCallback(path + ': ' + msg); | ||
} | ||
function error(msg) { | ||
context.info(path + ': ' + msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this call context.errorCallback
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thank you.
bd9e17d
to
e51285b
Compare
} | ||
// Scans for exports definitions in the body. | ||
var exportedNames = []; | ||
re = /\bexports.(\w+)\s*=\s/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While testing the PR locally, I wanted to check that the validator failed if an exports.<name>
wasn't present. In order to do that, I initially tested to just comment out a random exports.<name>
line. To my surprise, that didn't fail, which lead me to this line.
So my question is: Should this regexp be changed to also check that the line with exports.<name>
isn't commented out, since that would cause a runtime failure that the validator currently doesn't catch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we shall catch all of those cases by testing. And we usually enforce that during code review by not allowing commented code to be present. This a temporary solution anyway to just validate introduction of UMDs and keeping code quality until ES6 module imports will be introduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds fine to me!
(Since I happened to notice it, I figured that it couldn't hurt to ask.)
e51285b
to
de22058
Compare
de22058
to
b084dc0
Compare
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @brendandahl received. Current queue size: 0 Live output at: http://107.22.172.223:8877/876914199871804/output.txt |
From: Bot.io (Linux)ReceivedCommand cmd_test from @brendandahl received. Current queue size: 0 Live output at: http://107.21.233.14:8877/16c4337fe8456a5/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/876914199871804/output.txt Total script time: 19.77 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/16c4337fe8456a5/output.txt Total script time: 20.41 mins
|
Adds UMD headers to core, display and shared files.
Now each file is a module. There are some benefits: we can track dependencies between files and various module loading systems can be used, e.g. requirejs or node. Not so good news that we have some circular dependencies to deal with (I fixed/patched couple of them), e.g. colorspace uses image and image uses colorspace. I tried not to fix or refactor anything in this PR (only stuff to make modules dependencies valid). That's just an intermediate step the clean up the dependencies.
jshint globals directives were removed where was possible. I kept only PDFJS, however in the future we can refactor that too. Notice that we may try to turn "unused" on now.
There is validation tool 'external/umdutils/verifier.js' that helps to maintain UMD headers valid. See for UMD format definition there.
Future work might include: use module loading system for the viewer, remove UMD module headers during bundling, remove src/expose_to_global.js (which was created for unit tests), split some files into smaller (e.g. core/fonts.js), refactor PDFJS global more. After this is done we can individually refactor each module and even migrate to some e.g. ES6 translator.