mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Remove most build-time require
-calls from the src/display/
-folder
By leveraging import maps we can get rid of *most* of the remaining `require`-calls in the `src/display/`-folder, since we should strive to use modern `import`-statements wherever possible. The only remaining cases are Node.js-specific dependencies, since those seem very difficult to convert unless we start producing a bundle *specifically* for Node.js environments.
This commit is contained in:
parent
e81c084a92
commit
d022912719
11 changed files with 122 additions and 54 deletions
|
@ -31,14 +31,10 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|||
);
|
||||
}
|
||||
|
||||
const fs = __non_webpack_require__("fs");
|
||||
const http = __non_webpack_require__("http");
|
||||
const https = __non_webpack_require__("https");
|
||||
const url = __non_webpack_require__("url");
|
||||
|
||||
const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
|
||||
|
||||
function parseUrl(sourceUrl) {
|
||||
const url = __non_webpack_require__("url");
|
||||
const parsedUrl = url.parse(sourceUrl);
|
||||
if (parsedUrl.protocol === "file:" || parsedUrl.host) {
|
||||
return parsedUrl;
|
||||
|
@ -344,11 +340,13 @@ class PDFNodeStreamFullReader extends BaseFullReader {
|
|||
|
||||
this._request = null;
|
||||
if (this._url.protocol === "http:") {
|
||||
const http = __non_webpack_require__("http");
|
||||
this._request = http.request(
|
||||
createRequestOptions(this._url, stream.httpHeaders),
|
||||
handleResponse
|
||||
);
|
||||
} else {
|
||||
const https = __non_webpack_require__("https");
|
||||
this._request = https.request(
|
||||
createRequestOptions(this._url, stream.httpHeaders),
|
||||
handleResponse
|
||||
|
@ -391,11 +389,13 @@ class PDFNodeStreamRangeReader extends BaseRangeReader {
|
|||
|
||||
this._request = null;
|
||||
if (this._url.protocol === "http:") {
|
||||
const http = __non_webpack_require__("http");
|
||||
this._request = http.request(
|
||||
createRequestOptions(this._url, this._httpHeaders),
|
||||
handleResponse
|
||||
);
|
||||
} else {
|
||||
const https = __non_webpack_require__("https");
|
||||
this._request = https.request(
|
||||
createRequestOptions(this._url, this._httpHeaders),
|
||||
handleResponse
|
||||
|
@ -420,6 +420,7 @@ class PDFNodeStreamFsFullReader extends BaseFullReader {
|
|||
path = path.replace(/^\//, "");
|
||||
}
|
||||
|
||||
const fs = __non_webpack_require__("fs");
|
||||
fs.lstat(path, (error, stat) => {
|
||||
if (error) {
|
||||
if (error.code === "ENOENT") {
|
||||
|
@ -449,6 +450,7 @@ class PDFNodeStreamFsRangeReader extends BaseRangeReader {
|
|||
path = path.replace(/^\//, "");
|
||||
}
|
||||
|
||||
const fs = __non_webpack_require__("fs");
|
||||
this._setReadableStream(fs.createReadStream(path, { start, end: end - 1 }));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue